//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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2688 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
2816 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
283 ms |
3496 KB |
Output is correct |
2 |
Incorrect |
282 ms |
3372 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
494 ms |
3484 KB |
Output is correct |
2 |
Incorrect |
579 ms |
3072 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
811 ms |
3564 KB |
Output is correct |
2 |
Incorrect |
702 ms |
3240 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1114 ms |
3556 KB |
Output is correct |
2 |
Incorrect |
963 ms |
3200 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1762 ms |
3964 KB |
Output is correct |
2 |
Incorrect |
1926 ms |
3584 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2445 ms |
4216 KB |
Output is correct |
2 |
Incorrect |
2258 ms |
4088 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2991 ms |
4148 KB |
Output is correct |
2 |
Incorrect |
2938 ms |
3456 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3748 ms |
3852 KB |
Output is correct |
2 |
Incorrect |
3546 ms |
3544 KB |
Wrong number of edges |