# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223899 | 2020-04-16T20:16:23 Z | MKopchev | Pipes (CEOI15_pipes) | C++14 | 5000 ms | 15928 KB |
#include<bits/stdc++.h> using namespace std; const int nmax=1e5+42; vector< pair<int/*to*/,int/*id*/> > adj[nmax]; int in[nmax],low[nmax],t=0; int n,m; void dfs(int node,int par_edge) { if(in[node])return; t++; in[node]=t; low[node]=t; //cout<<t<<" -> "<<node<<endl; for(auto k:adj[node]) if(k.second!=par_edge) { if(in[k.first]==0)dfs(k.first,k.second); //cout<<"finished "<<node<<" "<<k.first<<" "<<low[k.first]<<endl; if(in[node]<in[k.first]&&in[node]<low[k.first]) { printf("%i %i\n",node,k.first); } else low[node]=min(low[k.first],low[node]); } } int parent[2][nmax]; int main() { scanf("%i%i",&n,&m); for(int i=1;i<=n;i++) { parent[0][i]=i; parent[1][i]=i; } int u,v; for(int i=1;i<=m;i++) { scanf("%i%i",&u,&v); bool keep=0; for(int j=0;j<2;j++) { int u_root=u,step_u=0; while(parent[j][u_root]!=u_root) { u_root=parent[j][u_root]; step_u++; } int v_root=v,step_v=0; while(parent[j][v_root]!=v_root) { v_root=parent[j][v_root]; step_v++; } if(u_root==v_root)continue; if(step_u<step_v)swap(u_root,v_root); parent[j][v_root]=u_root; keep=1; break; } if(keep==0)continue; adj[u].push_back({v,i}); adj[v].push_back({u,i}); } //cout<<" --- "<<endl; for(int i=1;i<=n;i++) if(in[i]==0)dfs(i,0); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 3328 KB | Output is correct |
2 | Correct | 11 ms | 3200 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 248 ms | 4136 KB | Output is correct |
2 | Correct | 216 ms | 4372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 457 ms | 4984 KB | Output is correct |
2 | Correct | 447 ms | 4728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 809 ms | 6656 KB | Output is correct |
2 | Correct | 731 ms | 6596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1506 ms | 13036 KB | Output is correct |
2 | Correct | 922 ms | 8568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2663 ms | 12800 KB | Output is correct |
2 | Correct | 2460 ms | 9424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3705 ms | 15112 KB | Output is correct |
2 | Correct | 2346 ms | 11000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4656 ms | 15928 KB | Output is correct |
2 | Correct | 3007 ms | 10964 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5065 ms | 9156 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |