# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1099011 |
2024-10-10T12:12:18 Z |
nikolashami |
Pipes (CEOI15_pipes) |
C++14 |
|
765 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
const int mxN=1e5+2;
vector<int>adj[mxN];
int ln[mxN],dp[mxN],vv[mxN];
int finde(int&x){
return x==ln[x]?x:ln[x]=finde(ln[x]);
}
void merge(int u,int v){
ln[finde(u)]=finde(v);
}
void dfs(int&u,int&p){
vv[u]=1;
for(int&v:adj[u]){
if(!(v^p))
continue;
dfs(v,u);
dp[u]^=dp[v];
}
}
void res(int&u,int&p){
vv[u]=1;
for(int&v:adj[u]){
if(!(v^p))
continue;
res(v,u);
if(!dp[v])
cout<<u<<' '<<v<<'\n';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
iota(ln,ln+n+1,0);
for(int i=0,u,v;i<m;++i){
cin>>u>>v;
if(finde(u)==finde(v)){
int xx=rng();
dp[u]^=xx;
dp[v]^=xx;
}else{
merge(u,v);
adj[u].push_back(v);
adj[v].push_back(u);
}
}
fill(vv,vv+n+1,0);
for(int fi=1,u,p;fi<=n;++fi){
if(vv[fi])
continue;
u=fi,p=0;
dfs(u,p);
}
fill(vv,vv+n+1,0);
for(int fi=1,u,p;fi<=n;++fi){
if(vv[fi])
continue;
u=fi,p=0;
res(u,p);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3000 KB |
Output is correct |
2 |
Correct |
3 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
2904 KB |
Output is correct |
2 |
Correct |
57 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
3164 KB |
Output is correct |
2 |
Correct |
114 ms |
3188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
3736 KB |
Output is correct |
2 |
Runtime error |
152 ms |
17796 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
5804 KB |
Output is correct |
2 |
Runtime error |
201 ms |
23756 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
6228 KB |
Output is correct |
2 |
Runtime error |
359 ms |
39612 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
6960 KB |
Output is correct |
2 |
Runtime error |
455 ms |
48468 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
585 ms |
6996 KB |
Output is correct |
2 |
Runtime error |
564 ms |
59956 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
15432 KB |
Output is correct |
2 |
Runtime error |
765 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |