#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5+1;
int n1[N];
int n2[N];
int fin1(int x){
if(n1[x]==x)
return x;
return n1[x]=fin1(n1[x]);
}
int fin2(int x){
if(n2[x]==x)
return x;
return n2[x]=fin2(n2[x]);
}
bool merge1(int a, int b){
a=fin1(a);
b=fin1(b);
if(a==b) return false;
n1[a]=b;
return true;
}
bool merge2(int a,int b){
a=fin2(a);
b=fin2(b);
if(a==b) return false;
n2[a]=b;
return true;
}
stack <int> T[N];
int tin[N];
int low[N];
bool vis[N];
int timer;
void dfs(int u, int par){
tin[u] = timer ++ ;
low[u] = tin[u];
vis[u] = true;
int x;
while(!T[u].empty()){
x = T[u].top();
T[u].pop();
if(x==par) continue;
if(vis[x]){
low[u] = min(low[u], tin[x]);
}
else{
dfs(x,u);
low[u] = min(low[u], low[x]);
if(tin[u]<low[x] && fin2(u) != fin2(x)){
cout << u << " " << x << "\n";
}
}
}
}
int main(){
fastIO;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++ ){
n1[i]=i;
n2[i]=i;
}
int u, v;
for(int i = 0 ; i < m ; i ++ ){
cin >> u >> v;
if(merge1(u,v)){
T[u].push(v);
T[v].push(u);
}
else if(merge2(u,v)){
T[u].push(v);
T[v].push(u);
}
}
for(int i = 1; i <= n; i ++ )if(!vis[i]) dfs(i,-1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
171 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
56 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
56 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
78 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
58 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
59 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
59 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
59 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
60 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
56 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |