# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97157 | 2019-02-14T07:32:54 Z | dndhk | Pipes (CEOI15_pipes) | C++14 | 1594 ms | 8332 KB |
#include <iostream> #include <vector> #include <stdio.h> #include <algorithm> #define MAX_N 100000 using namespace std; int N, M; struct S{ int x, y; bool operator <(const S &a)const{ if(x==a.x)return y<a.y; return x<a.x; } }; S gp[MAX_N*4+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 v[MAX_N+1]; int sz2; int a, b, A, B; 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].x<x) s = m+1; else e = m; } for(int i=s; i<sz; i++){ if(gp[i].x!=x) break; if(gp[i].y==p[x] && tf){ tf = false; continue; } if(lv[gp[i].y]!=0){ up[x] = min(up[x], lv[gp[i].y]); }else{ p[gp[i].y] = x; lv[gp[i].y] = lv[x]+1; dfs(gp[i].y); if(up[gp[i].y]>lv[x]) printf("%d %d\n", gp[i].y, x); up[x] = min(up[x], up[gp[i].y]); } } } int main(){ scanf("%d %d", &N, &M); for(int i=1; i<=N; i++) g1[i] = g2[i] = i; while(M--){ scanf("%d%d", &a, &b); A = a; while(g1[A]!=A){ v[sz2++] = A; A = g1[A]; } while(sz2>0){ g1[v[--sz2]] = A; } B = b; while(g1[B]!=B){ v[sz2++] = B; B = g1[B]; } while(sz2>0){ g1[v[--sz2]] = B; } if(A!=B){ gp[sz].x = a; gp[sz].y = b; sz++; gp[sz].x = b; gp[sz].y = a; sz++; g1[A] = B; continue; } A = a; B = b; while(g2[A]!=A){ v[sz2++] = A; A = g2[A]; } while(sz2>0){ g2[v[--sz2]] = A; } while(g2[B]!=B){ v[sz2++] = B; B = g2[B]; } while(sz2>0){ g2[v[--sz2]] = B; } if(A!=B){ gp[sz].x = a; gp[sz].y = b; sz++; gp[sz].x = b; gp[sz].y = a; sz++; 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 | 8 ms | 768 KB | Output is correct |
2 | Correct | 7 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 127 ms | 676 KB | Output is correct |
2 | Correct | 118 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 214 ms | 1148 KB | Output is correct |
2 | Correct | 249 ms | 888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 348 ms | 2296 KB | Output is correct |
2 | Correct | 294 ms | 2168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 489 ms | 6008 KB | Output is correct |
2 | Correct | 455 ms | 4344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 770 ms | 6904 KB | Output is correct |
2 | Correct | 756 ms | 5012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1054 ms | 8328 KB | Output is correct |
2 | Correct | 1022 ms | 5880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1269 ms | 8332 KB | Output is correct |
2 | Correct | 1280 ms | 5760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1594 ms | 7928 KB | Output is correct |
2 | Correct | 1451 ms | 6424 KB | Output is correct |