# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527352 | 2022-02-17T09:24:54 Z | jamielim | Pipes (CEOI15_pipes) | C++14 | 1434 ms | 17580 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb emplace_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int,int> ii; typedef pair<ii,ii> i4; const int MOD=1000000007; const int INF=1012345678; const ll LLINF=1012345678012345678LL; const double PI=3.1415926536; const double EPS=1e-14; const int MAXN=100005; int n,m; int par[MAXN],par2[MAXN]; int root(int x){return par[x]=(par[x]==x?x:root(par[x]));} int root2(int x){return par2[x]=(par2[x]==x?x:root2(par2[x]));} vector<int> adj[MAXN]; // only stores at most 2*tree bool vis[MAXN]; int p[MAXN],low[MAXN],dep[MAXN]; int ctr=1; void dfs(int x){ vis[x]=1; dep[x]=low[x]=ctr++; for(int i:adj[x]){ if(!vis[i]){ p[i]=x; dfs(i); if(low[i]>dep[x])printf("%d %d\n",x,i); low[x]=min(low[x],low[i]); }else if(i!=p[x])low[x]=min(low[x],dep[i]); } } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)par[i]=par2[i]=i; int a,b; for(int i=0;i<m;i++){ scanf("%d%d",&a,&b); //if a,b are in different trees, merge the two trees int ra=root(a),rb=root(b); if(ra!=rb){ par[ra]=rb; adj[a].pb(b); adj[b].pb(a); continue; } //otherwise, take note that later we have to get rid of the entire cycle int r2a=root2(a),r2b=root2(b); if(r2a!=r2b){ par2[r2a]=par2[r2b]; adj[a].pb(b); adj[b].pb(a); } } for(int i=1;i<=n;i++)if(!vis[i])dfs(i); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2636 KB | Output is correct |
2 | Incorrect | 1 ms | 2648 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 3172 KB | Output is correct |
2 | Incorrect | 6 ms | 3048 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 6828 KB | Output is correct |
2 | Incorrect | 112 ms | 6620 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 211 ms | 7792 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 365 ms | 11128 KB | Output is correct |
2 | Correct | 335 ms | 8900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 454 ms | 11320 KB | Output is correct |
2 | Incorrect | 387 ms | 7972 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 729 ms | 12756 KB | Output is correct |
2 | Incorrect | 672 ms | 9824 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 982 ms | 15712 KB | Output is correct |
2 | Incorrect | 911 ms | 10692 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1136 ms | 17580 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1434 ms | 15972 KB | Output is correct |
2 | Correct | 1378 ms | 12228 KB | Output is correct |