# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46925 | 2018-04-24T19:48:59 Z | HachikujiMayoi | Pipes (CEOI15_pipes) | C++14 | 5000 ms | 18976 KB |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m; int dep[N], par[N], dp[N][18], S[N], vis[N]; vector <int> g[N]; set <int> blocked; int Get(int a){ if(par[a] == a) return a; return par[a] = Get(par[a]); } void dfs(int at, int pr){ dp[at][0] = pr; vis[at] = 1; for(int i = 1; i <= 17; ++i) dp[at][i] = dp[ dp[at][i - 1] ][ i - 1 ]; for(auto i : g[at]){ if(i == pr) continue; dep[i] = dep[at] + 1; dfs(i, at); } } int lca(int a, int b){ if(dep[a] > dep[b]) swap(a, b); for(int i = 17; i >= 0; --i){ if(dep[b] - (1 << i) >= dep[a]){ a = dp[a][i]; } } if(a == b) return a; for(int i = 17; i >= 0; --i){ if(dp[a][i] != dp[b][i]){ a = dp[a][i]; b = dp[b][i]; } } return dp[a][0]; } void solve(int at, int pr){ vis[at] = 1; for(auto i : g[at]){ if(i == pr) continue; solve(i, at); S[at] += S[i]; } if(S[at] == 0 && pr){ printf("%d %d\n", at, pr); } } int main(){ int x, y; scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++i) par[i] = i; for(int i = 1; i <= m; ++i){ scanf("%d %d", &x, &y); if(Get(x) == Get(y)) continue; g[x].push_back(y); g[y].push_back(x); x = Get(x); y = Get(y); par[x] = y; blocked.insert(i); } for(int i = 1; i <= n; ++i){ if(!vis[i]){ dfs(i, 0); } } rewind(stdin); scanf("%d %d", &n, &m); for(int i = 1; i <= m; ++i){ scanf("%d %d", &x, &y); if(blocked.find(i) != blocked.end()) continue; int lc = lca(x, y); S[lc] -= 2; S[x] += 1; S[y] += 1; } memset(vis, 0, sizeof(vis)); for(int i = 1; i <= n; ++i){ if(!vis[i]){ solve(i, 0); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3072 KB | Output is correct |
2 | Incorrect | 4 ms | 3072 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 3812 KB | Output is correct |
2 | Incorrect | 12 ms | 3712 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 304 ms | 3676 KB | Output is correct |
2 | Incorrect | 293 ms | 3544 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 563 ms | 4540 KB | Output is correct |
2 | Incorrect | 648 ms | 4524 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 933 ms | 6840 KB | Output is correct |
2 | Correct | 758 ms | 7800 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1704 ms | 14188 KB | Output is correct |
2 | Incorrect | 1316 ms | 14284 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2377 ms | 15956 KB | Output is correct |
2 | Correct | 2072 ms | 15792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3291 ms | 18916 KB | Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 4249 ms | 18976 KB | Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5016 ms | 18116 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |