//https://oj.uz/problem/view/CEOI15_pipes
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;
typedef pair <int, int> ii;
vector <ii> 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 id){
int u = find(i), v = find(j);
if (u == v) return false;
pset[u] = v;
G[i].push_back(ii(j, id));
G[j].push_back(ii(i, id));
return true;
}
} a[2];
void dfs(int u, int p, int id){
num[u] = low[u] = ++cnt;
for (auto pr : G[u]){
int v = pr.first, x = pr.second;
if (x == id) continue;
if (num[v]){
low[u] = min(low[u], num[v]);
}
else{
dfs(v, u, x);
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, i)) a[1].Union(u, v, i);
}
// for (int i = 1; i <= n; i++) if (!num[i]) dfs(i, i, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
2688 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
3072 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
282 ms |
6836 KB |
Output is correct |
2 |
Incorrect |
278 ms |
6856 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
497 ms |
7032 KB |
Output is correct |
2 |
Incorrect |
632 ms |
14884 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
930 ms |
7956 KB |
Output is correct |
2 |
Runtime error |
743 ms |
18296 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1199 ms |
9332 KB |
Output is correct |
2 |
Runtime error |
1064 ms |
25720 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1861 ms |
12236 KB |
Output is correct |
2 |
Incorrect |
1786 ms |
10476 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2880 ms |
14620 KB |
Output is correct |
2 |
Incorrect |
2370 ms |
14840 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3058 ms |
14552 KB |
Output is correct |
2 |
Runtime error |
3050 ms |
62568 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3846 ms |
10976 KB |
Output is correct |
2 |
Runtime error |
3600 ms |
22880 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |