# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54895 | 2018-07-05T09:09:34 Z | 김세빈(#1509) | Pipes (CEOI15_pipes) | C++11 | 1596 ms | 7936 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; vector <int> V[101010]; 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, bool f) { int i, c; bool f2; D[p] = D[r] + 1; R[p] = x; c = K[p], K[p] = r; if(c != r) f2 = chk[p], chk[p] = f; if(chk[p]) P[p] = P[r]; else P[p] = r; for(auto t: V[p]){ if(t != r){ if(t == c) reorder(x, t, p, f2); else reorder(x, t, p, 0); } } } int color(int a, int b) { if(a == b) return a; if(D[a] > D[b]) chk[a] = 1, P[a] = color(P[a], b); else chk[b] = 1, P[b] = color(a, P[b]); } 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 color(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 | Incorrect | 4 ms | 2688 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2944 KB | Output is correct |
2 | Incorrect | 9 ms | 2944 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 126 ms | 2916 KB | Output is correct |
2 | Incorrect | 122 ms | 2816 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 258 ms | 3200 KB | Output is correct |
2 | Incorrect | 247 ms | 3232 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 356 ms | 3952 KB | Output is correct |
2 | Correct | 299 ms | 4188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 487 ms | 6264 KB | Output is correct |
2 | Incorrect | 441 ms | 6272 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 787 ms | 6864 KB | Output is correct |
2 | Correct | 806 ms | 6884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1024 ms | 7800 KB | Output is correct |
2 | Incorrect | 994 ms | 7936 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1312 ms | 7912 KB | Output is correct |
2 | Incorrect | 1255 ms | 7936 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1596 ms | 7560 KB | Output is correct |
2 | Correct | 1519 ms | 7928 KB | Output is correct |