# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927783 | 2024-02-15T10:38:04 Z | 79brue | Pipes (CEOI15_pipes) | C++17 | 1584 ms | 65536 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int K = 17; vector<int> link[100002]; int par[100002], LCADB[100002][K], sz[100002], depth[100002]; int val[100002]; inline int find(int x){ if(x==par[x]) return x; return find(par[x]); } inline void sps_dfs(int x){ depth[x] = depth[par[x]] + 1; for(int i=1; i<K; i++) LCADB[x][i] = LCADB[LCADB[x][i-1]][i-1]; for(int y: link[x]){ sps_dfs(y); } } inline void merge(int x, int y){ x = find(x), y = find(y); if(x==y) return; if(sz[x] < sz[y]) swap(x, y); LCADB[y][0] = par[y] = x, sz[x] += sz[y]; link[x].push_back(y); sps_dfs(y); } inline int getLCA(int x, int y){ if(depth[x] > depth[y]) swap(x, y); for(int d=1; d<K; d++) if((depth[y]-depth[x])&(1<<d)) y = LCADB[y][d]; if(x==y) return x; for(int d=K-1; d>=0; d--) if(LCADB[x][d] != LCADB[y][d]) x = LCADB[x][d], y = LCADB[y][d]; return par[x]; } int n, m; void dfs(int x){ for(int y: link[x]){ dfs(y); val[x] += val[y]; } } int main(){ scanf("%d %d", &n, &m); for(int i=1; i<=n; i++) par[i] = i, sz[i] = 1; while(m--){ int x, y; scanf("%d %d", &x, &y); if(find(x) == find(y)){ val[x]++, val[y]++; val[getLCA(x, y)] -= 2; } else merge(x, y); } for(int i=1; i<=n; i++) if(par[i] == i) dfs(i); for(int i=1; i<=n; i++){ if(par[i] != i && !val[i]) printf("%d %d\n", par[i], i); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 6492 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 6748 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 110 ms | 12004 KB | Output is correct |
2 | Incorrect | 121 ms | 11860 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 204 ms | 16436 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 338 ms | 25156 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 445 ms | 31860 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 777 ms | 44848 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1150 ms | 55996 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1329 ms | 65536 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1584 ms | 65536 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |