# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35985 | 2017-12-04T05:19:31 Z | funcsr | Pipes (CEOI15_pipes) | C++14 | 2784 ms | 13964 KB |
#include <bitset> #include <cassert> #include <vector> #define rep(i, n) for (int i=0; i<(n); i++) #define INF 1145141919 #define pb push_back using namespace std; struct UnionFind { int U[100000]; UnionFind(int N) { rep(i, N) U[i] = i; } int find(int x) { if (U[x] == x) return x; return U[x] = find(U[x]); } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; U[x] = y; } bool same(int x, int y) { return find(x) == find(y); } }; int N, M; vector<int> G[100000]; int R[100000]; int U[17][100000]; void dfs(int x, int p, int r) { R[x] = r; U[0][x] = p; for (int t : G[x]) { if (t == p) continue; dfs(t, x, r+1); } } inline int lca(int x, int y) { if (R[x] < R[y]) swap(x, y); return y; /* for (int b=16; b>=0; b--) if ((R[x]-R[y])>>b) x = U[b][x]; if (x == y) return x; for (int b=16; b>=0; b--) if (U[b][x] != U[b][y]) x = U[b][x], y = U[b][y]; return U[0][x]; */ } int T[100000]; int dfs2(int x, int p) { for (int t : G[x]) { if (t == p) continue; T[x] += dfs2(t, x); } if (p != -1 && T[x] == 0) printf("%d %d\n", x+1, p+1); int ret = T[x]; T[x] = INF; return ret; } signed main() { auto f = fopen("/dev/stdin", "r"); fscanf(f, "%d %d", &N, &M); auto uf = new UnionFind(N); auto backward = new bitset<6000000>(); rep(i, M) { int u, v; fscanf(f, "%d %d", &u, &v); u--, v--; if (!uf->same(u, v)) { backward->set(i); uf->unite(u, v); G[u].pb(v); G[v].pb(u); } } delete uf; rep(i, N) R[i] = -1; rep(i, N) if (R[i] == -1) dfs(i, -1, 0); rep(k, 16) rep(i, N) { if (U[k][i] == -1) U[k+1][i] = -1; U[k+1][i] = U[k][U[k][i]]; } fseek(f, 0, 0); int nn, nm; fscanf(f, "%d %d", &nn, &nm); assert(N == nn && M == nm); rep(i, M) { int u, v; fscanf(f, "%d %d", &u, &v); u--, v--; if (!backward->test(i)) { T[u]++; T[v]++; T[lca(u, v)]-=2; } } delete backward; rep(i, N) if (T[i] != INF) dfs2(i, -1); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 3456 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 17 ms | 3948 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 232 ms | 3812 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 395 ms | 4512 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 631 ms | 5988 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 834 ms | 10916 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1358 ms | 12012 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1878 ms | 13964 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2304 ms | 13880 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2784 ms | 13576 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |