# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54811 | 2018-07-05T07:08:20 Z | 강태규(#1507) | Pipes (CEOI15_pipes) | C++11 | 1399 ms | 6984 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n; struct link { int x; link * nxt; } db[200000]; int tp = 0; link * edge[100001]; int par[100001]; int dep[100001]; int par1[100001]; int sz1[100001]; int par2[100001]; int sz2[100001]; int gr[100001]; int find1(int x) { if (par1[x]) return par1[x] = find1(par1[x]); return x; } int find2(int x) { if (par2[x]) return par2[x] = find2(par2[x]); return x; } int merge1(int x, int y) { x = find1(x); y = find1(y); if (x == y) return 0; if (sz1[x] < sz1[y]) swap(x, y); par1[y] = x; sz1[x] += sz1[y]; return 1; } int merge2(int x, int y) { x = find2(x); y = find2(y); if (x == y) return 0; gr[y] = gr[x]; if (sz2[x] < sz2[y]) swap(x, y); par2[y] = x; sz2[x] += sz2[y]; return 1; } void dfs(int x, int p) { for (link * i = edge[x]; i; i = i->nxt) { if (i->x == p) continue; if (find2(i->x) != find2(x)) { par[gr[find2(i->x)]] = gr[find2(x)]; dep[gr[find2(i->x)]] = dep[gr[find2(x)]] + 1; } dfs(i->x, x); } } void addEdge(int x, int t) { link * ls = db + tp++; ls->x = t; ls->nxt = edge[x]; edge[x] = ls; } int main() { int m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { sz1[i] = 1; sz2[i] = 1; gr[i] = i; } while (m--) { int u, v; scanf("%d%d", &u, &v); if (find1(u) != find1(v)) { if (sz1[find1(u)] < sz1[find1(v)]) swap(u, v); addEdge(u, v); addEdge(v, u); par[gr[find2(v)]] = gr[find2(u)]; dep[gr[find2(v)]] = dep[gr[find2(u)]] + 1; dfs(v, u); merge1(u, v); } else if (gr[find2(u)] != gr[find2(v)]) { u = gr[find2(u)]; v = gr[find2(v)]; while (u != v) { if (dep[u] < dep[v]) swap(u, v); merge2(v, u); u = gr[find2(par[u])]; } } } for (int i = 1; i <= n; ++i) { for (link * j = edge[i]; j; j = j->nxt) { if (i < j->x) continue; if (gr[find2(i)] != gr[find2(j->x)]) printf("%d %d\n", i, j->x); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 356 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 640 KB | Output is correct |
2 | Correct | 5 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 118 ms | 624 KB | Output is correct |
2 | Correct | 116 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 207 ms | 996 KB | Output is correct |
2 | Correct | 247 ms | 1032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 339 ms | 1920 KB | Output is correct |
2 | Correct | 281 ms | 2296 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 422 ms | 4996 KB | Output is correct |
2 | Correct | 416 ms | 4956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 672 ms | 5712 KB | Output is correct |
2 | Correct | 682 ms | 5676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 911 ms | 6888 KB | Output is correct |
2 | Correct | 862 ms | 6904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1130 ms | 6940 KB | Output is correct |
2 | Correct | 1110 ms | 6984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1399 ms | 6628 KB | Output is correct |
2 | Correct | 1369 ms | 6948 KB | Output is correct |