# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527415 |
2022-02-17T11:22:14 Z |
joelau |
Pipes (CEOI15_pipes) |
C++14 |
|
1079 ms |
20920 KB |
#include <bits/stdc++.h>
using namespace std;
int N,M,ufds[100005], ufds1[100005], depth[100005], low[100005], p[100005];
vector<int> lst[100005];
int findSet(int i) {
return ufds[i] == i ? i : ufds[i] = findSet(ufds[i]);
}
void unionSet (int i, int j) {
int a = findSet(i), b = findSet(j);
if (a != b) ufds[a] = b;
}
int findSet1(int i) {
return ufds1[i] == i ? i : ufds1[i] = findSet1(ufds1[i]);
}
void unionSet1 (int i, int j) {
int a = findSet1(i), b = findSet1(j);
if (a != b) ufds1[a] = b;
}
void dfs (int x, int d) {
depth[x] = d, low[x] = d;
bool b = true;
for (int v: lst[x]) {
if (depth[v] == -1) {
p[v] = x;
dfs(v,d+1);
if (low[v] > depth[x]) cout << x+1 << ' ' << v+1 << '\n';
low[x] = min(low[x],low[v]);
}
else if (v == p[x] && b) b = false;
else low[x] = min(low[x],depth[v]);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> M;
for (int i = 0; i < N; ++i) ufds[i] = i, ufds1[i] = i;
for (int i = 0; i < M; ++i) {
int u,v; cin >> u >> v; u--, v--;
if (findSet(u) != findSet(v)) {
unionSet(u,v);
lst[u].push_back(v), lst[v].push_back(u);
}
else if (findSet1(u) != findSet1(v)) {
unionSet1(u,v);
lst[u].push_back(v), lst[v].push_back(u);
}
}
memset(depth,-1,sizeof(depth));
for (int i = 0; i < N; ++i) if (depth[i] == -1) dfs(i,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3660 KB |
Output is correct |
2 |
Correct |
5 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
7196 KB |
Output is correct |
2 |
Correct |
87 ms |
6948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
10168 KB |
Output is correct |
2 |
Correct |
179 ms |
8896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
14392 KB |
Output is correct |
2 |
Correct |
219 ms |
12056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
13044 KB |
Output is correct |
2 |
Correct |
286 ms |
8500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
514 ms |
14692 KB |
Output is correct |
2 |
Correct |
475 ms |
10984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
665 ms |
18344 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
806 ms |
20920 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1079 ms |
18104 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |