# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54887 | 2018-07-05T08:54:23 Z | 김세빈(#1509) | Pipes (CEOI15_pipes) | C++11 | 1610 ms | 8028 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; vector <int> V[101010], T; int P[101010], K[101010]; int R[101010], D[101010], S[101010]; bool chk[101010]; int n, m; void reorder(int x, int p, int r, int f) { int i, c; D[p] = D[r] + 1; R[p] = x; c = K[p], K[p] = P[p] = r; for(auto t: V[p]){ if(t != r){ if(t == c) reorder(x, t, p, chk[p]); else reorder(x, t, p, 0); } } if(c != r) chk[p] = f; } void check(int a, int b) { T.clear(); for(;a!=b;){ if(D[a] < D[b]){ T.push_back(b); b = P[b]; } else{ T.push_back(a); a = P[a]; } } for(auto t: T) P[t] = a, chk[t] = 1; } int main() { int i, a, b; scanf("%d%d", &n, &m); for(i=1;i<=n;i++){ S[i] = 1; R[i] = i; } for(i=1;i<=m;i++){ scanf("%d%d", &a, &b); if(R[a] != R[b]){ if(S[R[a]] > S[R[b]]) swap(a, b); V[a].push_back(b); V[b].push_back(a); S[R[b]] += S[R[a]]; reorder(R[b], a, b, 0); } else check(a, b); } for(i=1;i<=n;i++){ if(R[i] != i && !chk[i]) printf("%d %d\n", i, K[i]); } return 0; }
Compilation message
# | 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 | 7 ms | 2944 KB | Output is correct |
2 | Correct | 7 ms | 2944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 119 ms | 2916 KB | Output is correct |
2 | Correct | 118 ms | 2928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 3172 KB | Output is correct |
2 | Correct | 248 ms | 3248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 353 ms | 3940 KB | Output is correct |
2 | Correct | 305 ms | 4252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 496 ms | 6376 KB | Output is correct |
2 | Correct | 462 ms | 6404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 779 ms | 6932 KB | Output is correct |
2 | Correct | 837 ms | 6896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1089 ms | 7800 KB | Output is correct |
2 | Correct | 1038 ms | 8028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1325 ms | 7800 KB | Output is correct |
2 | Correct | 1249 ms | 7940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1610 ms | 7544 KB | Output is correct |
2 | Correct | 1540 ms | 7928 KB | Output is correct |