#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
typedef vector<ld> vld;
typedef pair<ld, ld> pld;
typedef vector<pi> vpi;
//typedef tree<ll, null_type, less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T>
ostream &operator<<(ostream &os, vector<T> &a) {
os << "[";
for (int i = 0; i < ll(a.size()); i++) { os << a[i] << ((i != ll(a.size() - 1) ? " " : "")); }
os << "]\n";
return os;
}
#define all(x) x.begin(),x.end()
#define YES out("YES")
#define NO out("NO")
#define out(x){cout << x << "\n"; return;}
#define GLHF ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define print(x){for(auto ait:x) cout << ait << " "; cout << "\n";}
#define pb push_back
#define umap unordered_map
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << "" << p.first << " " << p.second << "";
return os;
}
void usaco(string taskname) {
string fin = taskname + ".in";
string fout = taskname + ".out";
const char *FIN = fin.c_str();
const char *FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
}
template<typename T>
void read(vector<T> &v) {
int n = v.size();
for (int i = 0; i < n; i++)
cin >> v[i];
}
template<typename T>
vector<T> UNQ(vector<T> a) {
vector<T> ans;
for (T t: a)
if (ans.empty() || t != ans.back())
ans.push_back(t);
return ans;
}
ll ceil(ll a, ll b) {
ll ans = a / b;
if (a % b)ans++;
return ans;
}
ld log(ld a, ld b) { return log(b) / log(a); }
ll power(ll base, ll exp, ll M = 1e18) {//(base^exp)%M
ll ans = 1;
while (exp) {
if (exp % 2 == 1)ans = ((ans % M) * (base % M)) % M;
base = ((base % M) * (base % M)) % M;
exp /= 2;
}
return ans;
}
string to_base(int n, int new_base) {
string s;
int nn = n;
while (nn) {
s += to_string(nn % new_base);
nn /= new_base;
}
reverse(all(s));
return s;
}
ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (b == 0)return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll x = (a / gcd(a, b));
return b * x;
}
vl generate_array(ll n, ll mn = 1, ll mx = 1e18 + 1) {
if (mx == 1e18 + 1)
mx = n;
vl ans(n);
for (int i = 0; i < n; i++)
ans[i] = (mn + rand() % (mx - mn + 1));
return ans;
}
string substr(string s, int l, int r) {
string ans;
for (int i = l; i <= r; i++)
ans += s[i];
return ans;
}
void solve();
int main() {
GLHF;
int t = 1;
//cin >> t;
while (t--)
solve();
}
struct DSU{
int par[int(1e5+1)];
DSU(){
for(int i=1; i<=1e5; i++)
par[i]=i;
}
int get(int x){return par[x]=(x==par[x]?x:get(par[x]));}
void unite(int u,int v){
u=get(u),v=get(v);
if(u==v)
return;
par[u]=v;
}
};
const int maxn=1e5+1;
int t = 0;
int dis[maxn], lo[maxn];
vector< int > graph[maxn];
void dfs(int x, int parr) {
dis[x] = t++;
lo[x] = dis[x];
//printf("start %d %d\n", x, dis[x]);
bool flag = false;
for (int tren : graph[x]) {
if (tren == parr && !flag) {
flag = true;
continue;
}
if (dis[tren] == -1) {
dfs(tren, x);
if (lo[tren] > dis[x]) cout << x << " " << tren << "\n";
lo[x] = min(lo[x], lo[tren]);
} else {
lo[x] = min(lo[x], dis[tren]);
}
}
//printf("end %d: %d %d\n", x, dis[x], lo[x]);
}
void solve() {
int n,m;
cin >> n >> m;
DSU d1,d2;
for(int i=0; i<m; i++){
int u,v;
cin >> u >> v;
if(d1.get(u)!=d1.get(v)){
d1.unite(u,v);
graph[u].pb(v);
graph[v].pb(u);
}
else if(d2.get(u)!=d2.get(v)){
d2.unite(u,v);
graph[u].pb(v);
graph[v].pb(u);
}
}
memset(dis, -1, sizeof dis);
for (int i = 1; i <= n; i++) {
if (dis[i] == -1) dfs(i, 0);
}
}
/*
80 171
76 13
1 71
13 34
17 31
40 26
39 18
19 26
56 21
18 74
26 33
18 32
6 20
22 50
4 5
61 54
36 15
29 15
30 51
38 10
31 66
35 70
29 50
6 7
75 47
18 46
45 73
31 10
34 20
4 25
73 24
69 6
73 17
20 6
37 30
43 71
4 67
1 2
62 20
72 44
38 59
53 46
49 70
31 38
40 33
63 21
54 40
49 77
45 17
50 64
63 56
20 69
69 20
9 44
27 6
58 51
46 60
23 9
28 42
44 65
23 9
36 29
15 71
76 55
17 73
54 68
8 1
4 18
72 44
39 18
54 40
28 14
22 71
48 20
32 11
39 18
20 62
45 59
1 43
58 2
17 52
63 77
25 39
55 27
7 63
3 4
8 50
65 37
34 20
26 61
40 19
77 21
44 51
23 51
19 26
21 56
60 25
18 46
42 14
52 24
4 11
24 59
68 47
51 58
7 35
77 49
2 3
24 66
33 54
31 73
69 20
58 16
44 2
6 62
66 24
17 73
12 19
10 73
77 63
38 52
27 41
59 38
6 55
20 6
38 59
60 39
51 44
49 7
2 9
24 73
24 17
46 39
38 45
5 6
35 49
71 50
64 8
16 2
56 7
62 20
1 64
29 22
19 47
12 19
68 54
10 17
50 43
22 71
22 1
66 24
16 37
8 64
41 48
3 59
5 47
8 71
53 60
25 4
21 56
70 49
4 32
56 28
69 55
43 22
3 59
39 32
70 14
19 68
48 62
44 37
73 66
42 14
*/
Compilation message
pipes.cpp: In function 'void usaco(std::string)':
pipes.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(FIN, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen(FOUT, "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3788 KB |
Output is correct |
2 |
Correct |
2 ms |
3788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4172 KB |
Output is correct |
2 |
Correct |
6 ms |
4044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
4100 KB |
Output is correct |
2 |
Correct |
104 ms |
3908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
4716 KB |
Output is correct |
2 |
Correct |
217 ms |
4324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
304 ms |
6192 KB |
Output is correct |
2 |
Correct |
292 ms |
5912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
447 ms |
10868 KB |
Output is correct |
2 |
Correct |
413 ms |
7392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
714 ms |
11932 KB |
Output is correct |
2 |
Correct |
661 ms |
9156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
953 ms |
13968 KB |
Output is correct |
2 |
Correct |
871 ms |
9016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1187 ms |
13968 KB |
Output is correct |
2 |
Runtime error |
1107 ms |
61980 KB |
Memory limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1423 ms |
13372 KB |
Output is correct |
2 |
Runtime error |
1827 ms |
65536 KB |
Memory limit exceeded |