# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223902 | 2020-04-16T20:25:09 Z | MKopchev | Pipes (CEOI15_pipes) | C++14 | 1797 ms | 24068 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,u_help=u,step_u=0; while(parent[j][u_root]!=u_root) { u_root=parent[j][u_root]; step_u++; } int mem; while(u_help!=u_root) { mem=parent[j][u_help]; parent[j][u_help]=u_root; u_help=mem; } int v_root=v,v_help=v,step_v=0; while(parent[j][v_root]!=v_root) { v_root=parent[j][v_root]; step_v++; } while(v_help!=v_root) { mem=parent[j][v_help]; parent[j][v_help]=v_root; v_help=mem; } //cout<<j<<" "<<u_root<<" "<<v_root<<endl; //for(int i=1;i<=n;i++)cout<<parent[j][i]<<" ";cout<<endl; 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<<"added "<<u<<" "<<v<<endl; } //cout<<" --- "<<endl; for(int i=1;i<=n;i++) if(in[i]==0)dfs(i,0); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2688 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 3328 KB | Output is correct |
2 | Correct | 10 ms | 3200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 157 ms | 3320 KB | Output is correct |
2 | Correct | 159 ms | 3196 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 268 ms | 4088 KB | Output is correct |
2 | Correct | 328 ms | 3692 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 445 ms | 5796 KB | Output is correct |
2 | Correct | 381 ms | 5376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 576 ms | 11640 KB | Output is correct |
2 | Correct | 508 ms | 8568 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 901 ms | 12796 KB | Output is correct |
2 | Correct | 889 ms | 9392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1191 ms | 15112 KB | Output is correct |
2 | Correct | 1126 ms | 11136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1464 ms | 15352 KB | Output is correct |
2 | Correct | 1415 ms | 11000 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1797 ms | 14492 KB | Output is correct |
2 | Runtime error | 1767 ms | 24068 KB | Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |