-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE.cpp
72 lines (63 loc) · 1.12 KB
/
E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
const int mxm = 1e5 + 100;
vector <int> adj[mxm],vis(mxm),in(mxm),low(mxm);
int timer;
bool exists;
vector <pair<int,int>> path;
void dfs(int node, int par) {
vis[node] = 1;
in[node] = low[node] = timer++;
for(auto child: adj[node]) {
if(child == par) {
continue;
}
if(vis[child] == 1) {
low[node] = min(low[node],low[child]);
if(in[node] > in[child]) {
path.pb(mp(node,child));
}
}
else {
dfs(child, node);
if(low[child] > in[node]) {
exists = false;
return;
}
path.pb(mp(node,child));
low[node] = min(low[node], low[child]);
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n,m,a,b;
cin >> n >> m;
path.clear();
for(int i=1;i<=n;i++) {
vis[i] = 0;
in[i] = 0;
low[i] = 0;
adj[i].clear();
}
for(int i=0;i<m;i++) {
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
timer = 0;
exists = true;
dfs(1,-1);
if(!exists) {
cout << 0;
}
else {
for(auto u: path) {
cout << u.first << " " << u.second << '\n';
}
}
return 0;
}