# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167288 | 2019-12-07T08:02:17 Z | mhy908 | Pipes (CEOI15_pipes) | C++14 | 1816 ms | 29016 KB |
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define F first #define S second using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; struct UNION_FIND{ int par[100001]; UNION_FIND(){for(int i=1; i<=100000; i++)par[i]=i;} int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);} void mergepar(int a, int b){par[findpar(a)]=findpar(b);} bool query(int a, int b){return findpar(a)==findpar(b);} }uf1, uf2; vector<int> link[100001]; int n, m; int disc[100001], lowlink[100001], par[100001], t; void dfs(int u) { disc[u]=lowlink[u]=++t; bool temp=false; for(int i=0; i<link[u].size(); i++){ if(link[u][i]==par[u]&&!temp)temp=true; else{ if(!disc[link[u][i]]){ par[link[u][i]]=u; dfs(link[u][i]); if(lowlink[link[u][i]]>disc[u])printf("%d %d\n", u, link[u][i]); lowlink[u]=min(lowlink[u], lowlink[link[u][i]]); } else lowlink[u]=min(lowlink[u], disc[link[u][i]]); } } } int main() { scanf("%d %d", &n, &m); for(int i=1; i<=m; i++){ int u, v; scanf("%d %d", &u, &v); if(!uf1.query(u, v)){ uf1.mergepar(u, v); link[u].pb(v); link[v].pb(u); } else if(!uf2.query(u, v)){ uf2.mergepar(u, v); link[u].pb(v); link[v].pb(u); } } for(int i=1; i<=n; i++){ if(!disc[i])dfs(i); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3448 KB | Output is correct |
2 | Correct | 8 ms | 3532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 3960 KB | Output is correct |
2 | Correct | 10 ms | 3832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 144 ms | 7988 KB | Output is correct |
2 | Correct | 143 ms | 4216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 245 ms | 5112 KB | Output is correct |
2 | Correct | 334 ms | 4856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 419 ms | 7272 KB | Output is correct |
2 | Correct | 356 ms | 9896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 620 ms | 11368 KB | Output is correct |
2 | Correct | 544 ms | 12596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 945 ms | 14164 KB | Output is correct |
2 | Correct | 868 ms | 13336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1233 ms | 15084 KB | Output is correct |
2 | Correct | 1160 ms | 15084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1542 ms | 15272 KB | Output is correct |
2 | Runtime error | 1455 ms | 16752 KB | Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1816 ms | 15232 KB | Output is correct |
2 | Runtime error | 1711 ms | 29016 KB | Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |