//https://oj.uz/problem/view/CEOI15_pipes
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;
vector <int> G[N];
int n, m, low[N], num[N], cnt;
struct dsu{
int pset[N];
void init(){
for (int i = 1; i <= n; i++) pset[i] = i;
}
int find(int i) {return ((pset[i] == i) ? i : pset[i] = find(pset[i]));}
bool Union(int i, int j){
int u = find(i), v = find(j);
if (u == v) return false;
pset[u] = v;
G[i].push_back(j);
G[j].push_back(i);
return true;
}
} a[2];
void dfs(int u, int p){
num[u] = low[u] = ++cnt;
for (auto v : G[u]){
if (v == p) continue;
if (num[v]){
low[u] = min(low[u], num[v]);
}
else{
dfs(v, u);
low[u] = min(low[u], low[v]);
}
}
if (u != p && low[u] >= num[u]) cout << u << " " << p << "\n";
}
int main(){
cin >> n >> m;
a[0].init(); a[1].init();
for (int i = 1; i <= m; i++){
int u, v; cin >> u >> v;
if (!a[0].Union(u, v)) a[1].Union(u, v);
}
for (int i = 1; i <= n; i++) if (!num[i]) dfs(i, i);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2688 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3200 KB |
Output is correct |
2 |
Incorrect |
11 ms |
3072 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
8484 KB |
Output is correct |
2 |
Incorrect |
279 ms |
8252 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
502 ms |
13260 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
885 ms |
21248 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1188 ms |
10724 KB |
Output is correct |
2 |
Runtime error |
1073 ms |
25464 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1929 ms |
24120 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2584 ms |
16668 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3029 ms |
22424 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3725 ms |
34888 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |