# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1098960 |
2024-10-10T11:36:05 Z |
nikolashami |
Pipes (CEOI15_pipes) |
C++14 |
|
717 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];
bitset<mxN>vv;
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';
}
}
int32_t 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);
}
}
vv.reset();
for(int fi=1,u,p;fi<=n;++fi){
if(vv[fi])
continue;
u=fi,p=0;
dfs(u,p);
}
vv.reset();
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 |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2904 KB |
Output is correct |
2 |
Correct |
4 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
8184 KB |
Output is correct |
2 |
Correct |
64 ms |
8048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
12780 KB |
Output is correct |
2 |
Correct |
124 ms |
14420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
177 ms |
19840 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
268 ms |
26112 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
368 ms |
39168 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
494 ms |
50516 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
615 ms |
62176 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
717 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |