# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527330 |
2022-02-17T08:15:37 Z |
joelau |
Pipes (CEOI15_pipes) |
C++14 |
|
1032 ms |
26272 KB |
#include <bits/stdc++.h>
using namespace std;
int N,M, ufds[100005], rnk[100005], ufds1[100005], rnk1[100005], low[100005], depth[100005], p[100005];
vector< pair<int,int> > lst[100005];
bitset<100005> visited;
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) return;
if (rnk[a] < rnk[b]) ufds[a] = b;
if (rnk[a] > rnk[b]) ufds[b] = a;
if (rnk[a] == rnk[b]) ufds[a] = b, rnk[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) return;
if (rnk1[a] < rnk1[b]) ufds1[a] = b;
if (rnk1[a] > rnk1[b]) ufds1[b] = a;
if (rnk1[a] == rnk1[b]) ufds1[a] = b, rnk1[b]++;
}
void dfs (int u, int d) {
visited[u] = 1, depth[u] = d, low[u] = d;
for (auto v: lst[u]) {
if (!visited[v.first]) {
p[v.first] = v.second;
dfs(v.first,d+1);
if (low[v.first] > depth[u]) cout << u+1 << ' ' << v.first+1 << '\n';
low[u] = min(low[u],low[v.first]);
}
else if (v.second != p[u])
low[u] = min(low[u],depth[v.first]);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> M;
for (int i = 0; i < N; ++i) ufds[i] = i, rnk[i] = 1, ufds1[i] = i, rnk1[i] = 1;
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].emplace_back(v,i), lst[v].emplace_back(u,i);
}
else if (findSet1(u) != findSet1(v)) {
unionSet1(u,v);
lst[u].emplace_back(v,i), lst[v].emplace_back(u,i);
}
}
for (int i = 0; i < N; ++i) if (!visited[i]) dfs(i,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3412 KB |
Output is correct |
2 |
Correct |
5 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
8700 KB |
Output is correct |
2 |
Correct |
89 ms |
8296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
12412 KB |
Output is correct |
2 |
Correct |
180 ms |
14816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
286 ms |
18020 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
14428 KB |
Output is correct |
2 |
Correct |
288 ms |
9932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
516 ms |
16308 KB |
Output is correct |
2 |
Correct |
565 ms |
11896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
677 ms |
20128 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
858 ms |
26272 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1032 ms |
20136 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |