//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();
int u, v;
for (int i = 1; i <= m; i++){
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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3344 KB |
Output is correct |
2 |
Correct |
12 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
289 ms |
3192 KB |
Output is correct |
2 |
Correct |
289 ms |
3084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
505 ms |
4088 KB |
Output is correct |
2 |
Correct |
613 ms |
14812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
944 ms |
5752 KB |
Output is correct |
2 |
Runtime error |
870 ms |
19176 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1238 ms |
11436 KB |
Output is correct |
2 |
Correct |
1052 ms |
8544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1841 ms |
12844 KB |
Output is correct |
2 |
Correct |
1815 ms |
12332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2409 ms |
15224 KB |
Output is correct |
2 |
Correct |
2503 ms |
15548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3371 ms |
15244 KB |
Output is correct |
2 |
Runtime error |
3005 ms |
64028 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3724 ms |
14364 KB |
Output is correct |
2 |
Runtime error |
3477 ms |
65536 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |