#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size
const int mxN = 1e5;
int n,m;
vector<int> adj[mxN];
int p[2*mxN];
void dfs(int c, int depth, int par){
p[c] = depth;
p[c+n] = p[c];
int op = par;
for (int i : adj[c]){
if (i == par){par = -1; continue;}
if (p[i] != -1){ p[c+n] = min(p[c+n],p[i]); continue;}
dfs(i,depth+1,c);
p[c+n] = min(p[c+n], p[i+n]);
}
if (p[c+n] >= depth && op != -1) cout << c+1 << " " << op+1 << '\n';
}
int gpar(const int &c){
if (p[c] == c) return c;
p[c] = gpar(p[c]);
return p[c];
}
bool ss(const int &a, const int &b){
return gpar(a) == gpar(b);
}
void un(const int &a, const int &b){
p[gpar(a)] = gpar(b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < 2* n; i++) p[i] = i;
int a,b;
for (int i = 0; i < m; i++){
cin >> a >> b;
a -= 1;
b -= 1;
if (!ss(a,b)) un(a,b);
else if (!ss(a+n,b+n)) un(a+n,b+n);
else continue;
adj[a].pb(b);
adj[b].pb(a);
}
for (int i = 0; i < n; i++) p[i] = -1;
for (int i = 0; i < n; i++) if (p[i] == -1) dfs(i,0,-1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3160 KB |
Output is correct |
2 |
Correct |
4 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
2972 KB |
Output is correct |
2 |
Correct |
55 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
3764 KB |
Output is correct |
2 |
Correct |
128 ms |
3240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
5456 KB |
Output is correct |
2 |
Correct |
166 ms |
5044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
246 ms |
10836 KB |
Output is correct |
2 |
Correct |
216 ms |
6660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
376 ms |
11856 KB |
Output is correct |
2 |
Correct |
366 ms |
8696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
482 ms |
14200 KB |
Output is correct |
2 |
Correct |
464 ms |
8352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
604 ms |
14220 KB |
Output is correct |
2 |
Correct |
567 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
13464 KB |
Output is correct |
2 |
Runtime error |
713 ms |
23528 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |