# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54889 | 2018-07-05T08:57:30 Z | 김세빈(#1509) | Pipes (CEOI15_pipes) | C++11 | 1685 ms | 7932 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, 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; } 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 | 2668 KB | Output is correct |
2 | Correct | 3 ms | 2716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 2920 KB | Output is correct |
2 | Correct | 7 ms | 2944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 123 ms | 2816 KB | Output is correct |
2 | Correct | 122 ms | 2892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 213 ms | 3200 KB | Output is correct |
2 | Correct | 258 ms | 3244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 365 ms | 3960 KB | Output is correct |
2 | Correct | 311 ms | 4260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 519 ms | 6388 KB | Output is correct |
2 | Correct | 457 ms | 6348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 824 ms | 7032 KB | Output is correct |
2 | Correct | 751 ms | 6776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1024 ms | 7804 KB | Output is correct |
2 | Correct | 995 ms | 7928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1303 ms | 7800 KB | Output is correct |
2 | Correct | 1259 ms | 7932 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1685 ms | 7636 KB | Output is correct |
2 | Correct | 1602 ms | 7828 KB | Output is correct |