//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; bool ck = false;
for (auto v : G[u]){
if (v == p && !ck) {ck = true; 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);
}
# |
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 |
12 ms |
3200 KB |
Output is correct |
2 |
Correct |
11 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
3012 KB |
Output is correct |
2 |
Correct |
283 ms |
2876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
495 ms |
3720 KB |
Output is correct |
2 |
Correct |
578 ms |
3300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
922 ms |
5148 KB |
Output is correct |
2 |
Correct |
718 ms |
4836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1181 ms |
9932 KB |
Output is correct |
2 |
Correct |
1046 ms |
7116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2029 ms |
11064 KB |
Output is correct |
2 |
Correct |
1769 ms |
8576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2571 ms |
13048 KB |
Output is correct |
2 |
Correct |
2356 ms |
8936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3050 ms |
13000 KB |
Output is correct |
2 |
Correct |
2967 ms |
8916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4027 ms |
12484 KB |
Output is correct |
2 |
Correct |
3680 ms |
10184 KB |
Output is correct |