# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97142 | 2019-02-14T04:36:58 Z | dndhk | Pipes (CEOI15_pipes) | C++14 | 345 ms | 2680 KB |
#include <iostream> #include <vector> #include <stdio.h> #include <algorithm> #define MAX_N 100000 using namespace std; int N, M; pair<int, int> gp[MAX_N*2+1]; int sz = 0; int g1[MAX_N+1], g2[MAX_N+1]; int up[MAX_N+1], lv[MAX_N+1], p[MAX_N+1]; int find_g1(int x){ if(x==g1[x]) return x; return g1[x] = find_g1(g1[x]); } int find_g2(int x){ if(x==g2[x]) return x; return g2[x] = find_g2(g2[x]); } int s, e, m; void dfs(int x){ bool tf = true; up[x] = lv[x]; s = 0, e = sz-1; while(s<e){ m = (s+e)/2; if(gp[m].first<x) s = m+1; else e = m; } for(int i=s; i<sz; i++){ if(gp[i].first!=x) break; if(gp[i].second==p[x] && tf){ tf = false; continue; } if(lv[gp[i].second]!=0){ up[x] = min(up[x], lv[gp[i].second]); }else{ p[gp[i].second] = x; lv[gp[i].second] = lv[x]+1; dfs(gp[i].second); if(up[gp[i].second]>lv[x]) printf("%d %d\n", gp[i].second, x); up[x] = min(up[x], up[gp[i].second]); } } } int main(){ scanf("%d %d", &N, &M); for(int i=1; i<=N; i++) g1[i] = g2[i] = i; int a, b; while(M--){ scanf("%d%d", &a, &b); if(find_g1(a)!=find_g1(b)){ gp[sz++] = {a, b}; gp[sz++] = {b, a}; a = find_g1(a); b = find_g1(b); g1[a] = b; } else if(find_g2(a)!=find_g2(b)){ gp[sz++] = {a, b}; gp[sz++] = {b, a}; a = find_g2(a); b = find_g2(b); g2[a] = b; } }sort(gp, gp+sz); for(int i=1; i<=N; i++){ if(lv[i]==0){ lv[i] = 1; dfs(i); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 680 KB | Output is correct |
2 | Correct | 6 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 122 ms | 640 KB | Output is correct |
2 | Correct | 118 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 208 ms | 1140 KB | Output is correct |
2 | Correct | 240 ms | 868 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 345 ms | 2200 KB | Output is correct |
2 | Correct | 300 ms | 2064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 35 ms | 2424 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 33 ms | 2524 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 32 ms | 2680 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 37 ms | 2608 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 40 ms | 2580 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |