# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49178 | 2018-05-23T06:32:57 Z | Namnamseo | Pipes (CEOI15_pipes) | C++17 | 1449 ms | 12488 KB |
#include <cstdio> #include <vector> using namespace std; #define pb push_back typedef pair<int,int> pp; int n, m; struct unf { int par[100010]; void init(){ for(int i=1; i<=n; ++i) par[i]=i; } int root(int x){ return (x==par[x])?x:(par[x]=root(par[x])); } bool merge(int a,int b){ a=root(a); b=root(b); if(a==b) return false; par[a]=b; return true; } } f1, f2; int par[100010]; int idx[100010]; int lowl[100010]; int nt; vector<int> edge[100010]; void dfs(int x){ idx[x] = lowl[x] = ++nt; bool cl = false; for(int y:edge[x]){ if(par[x] == y && !cl){ cl=true; continue; } if(!idx[y]){ par[y]=x; dfs(y); lowl[x] = min(lowl[x], lowl[y]); } else lowl[x] = min(lowl[x], idx[y]); } if(par[x] && idx[x]==lowl[x]) printf("%d %d\n", x, par[x]); } int main(){ scanf("%d%d", &n, &m); f1.init(); f2.init(); for(;m--;){ int a,b; scanf("%d%d", &a, &b); if(f1.merge(a,b) || f2.merge(a,b)) edge[a].pb(b), edge[b].pb(a); } for(int i=1; i<=n; ++i) if(par[i]==0) dfs(i); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2660 KB | Output is correct |
2 | Correct | 3 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 3072 KB | Output is correct |
2 | Correct | 8 ms | 2944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 111 ms | 3008 KB | Output is correct |
2 | Correct | 108 ms | 2936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 195 ms | 3572 KB | Output is correct |
2 | Correct | 229 ms | 3320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 323 ms | 5004 KB | Output is correct |
2 | Correct | 279 ms | 4868 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 492 ms | 9532 KB | Output is correct |
2 | Correct | 405 ms | 7160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 825 ms | 10648 KB | Output is correct |
2 | Correct | 688 ms | 8684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 995 ms | 12488 KB | Output is correct |
2 | Correct | 882 ms | 9164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1186 ms | 12476 KB | Output is correct |
2 | Correct | 1154 ms | 9164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1449 ms | 11968 KB | Output is correct |
2 | Correct | 1385 ms | 9976 KB | Output is correct |