# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96859 | 2019-02-12T14:04:46 Z | Retro3014 | Pipes (CEOI15_pipes) | C++17 | 1024 ms | 4728 KB |
#include <stdio.h> #include <vector> #include <algorithm> #include <iostream> using namespace std; #define MAX_N 30000 #define LN 17 typedef long long ll; typedef pair<int, int> pii; int N, M; vector<pii > gp[MAX_N+1]; int num[MAX_N+1]; int p[MAX_N+1][LN]; int up[MAX_N+1]; int lv[MAX_N+1]; bool vst[MAX_N+1]; int find_g(int x){ for(int i=LN-1; i>=0; i--){ if(p[x][i]!=0){ x = p[x][i]; } } return x; } pii edge[MAX_N+1]; bool chk[MAX_N+1]; int sz = 0; int lca(int x, int y){ for(int i=LN-1; i>=0; i--){ //cout<<i<<' '<<x<<' '<<y<<endl; if(lv[p[x][i]]>=lv[y]){ x = p[x][i]; } if(lv[p[y][i]]>=lv[x]){ y = p[y][i]; } } for(int i=LN-1; i>=0; i--){ if(p[x][i]!=p[y][i]){ x = p[x][i]; y = p[y][i]; } } if(x!=y) x = p[x][0]; return x; } void dfs(int x){ for(int i=0; i<gp[x].size(); i++){ if(gp[x][i].first==p[x][0]) continue; dfs(gp[x][i].first); if(up[gp[x][i].first]<=lv[x]) chk[gp[x][i].second] = false; up[x] = min(up[x], up[gp[x][i].first]); } } void init_graph(int x){ up[x] = lv[x]; for(int i=1; i<LN; i++) p[x][i] = p[p[x][i-1]][i-1]; for(int i=0; i<gp[x].size(); i++){ if(gp[x][i].first==p[x][0]) continue; lv[gp[x][i].first] = lv[x]+1; p[gp[x][i].first][0] = x; init_graph(gp[x][i].first); } } int main(){ scanf("%d%d", &N, &M); for(int i=1; i<=N; i++) num[i] = 1; int a, b, k, tmp, t; int A, B; for(int i=1; i<=N; i++){ lv[i] = up[i] = 1; } while(M--){ scanf("%d%d", &a, &b); A = find_g(a); B = find_g(b); if(A==B){ //cout<<'*'<<a<<' '<<b<<endl; k = lca(a, b); //cout<<k<<endl; up[a] = min(up[a], lv[k]); up[b] = min(up[b], lv[k]); }else{ if(num[A]>=num[B]){ tmp = a; a = b; b = tmp; tmp = A; A = B; B = tmp; } t = num[A]; dfs(A); for(int i=1; i<LN; i++){ p[a][i] = 0; }p[a][0] = b; lv[a] = lv[b]+1; //printf("%d %d\n", a, b); gp[a].push_back({b, sz}); gp[b].push_back({a, sz}); init_graph(a); edge[sz] = {a, b}; chk[sz] = true; sz++; num[B] += t; } } for(int i=1; i<=N; i++){ int k = find_g(i); if(!vst[k]){ vst[k] = true; dfs(k); } } for(int i=0; i<sz; i++){ if(chk[i]){ printf("%d %d\n", edge[i].first, edge[i].second); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1152 KB | Output is correct |
2 | Correct | 2 ms | 1024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 1660 KB | Output is correct |
2 | Correct | 10 ms | 1536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 289 ms | 1528 KB | Output is correct |
2 | Correct | 285 ms | 1528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 581 ms | 2268 KB | Output is correct |
2 | Correct | 684 ms | 2268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1024 ms | 3992 KB | Output is correct |
2 | Correct | 801 ms | 4728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 2816 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 3072 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 3056 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 3072 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 4 ms | 3072 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |