# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
86570 |
2018-11-26T15:45:05 Z |
rzbt |
Pipes (CEOI15_pipes) |
C++14 |
|
4611 ms |
7344 KB |
#include <bits/stdc++.h>
#define MAXN 100005
#define pb push_back
#define mp make_pair
using namespace std;
int n,m;
int otacs[MAXN],vels[MAXN],otaco[MAXN],velo[MAXN];
vector<pair<int,int> > grane;
set<pair<int,int> > s,s2;
vector<pair<int,int> > fusg;
int predak(int p,int *otac,int *vel){
while(p!=otac[p]){
otac[p]=otac[otac[p]];
p=otac[p];
}
return p;
}
void spoji(int a,int b,int *otac,int *vel){
a=predak(a,otac,vel);
b=predak(b,otac,vel);
if(a==b)return;
if(vel[a]<vel[b])swap(a,b);
otac[b]=a;
vel[a]+=vel[b];
}
void init(){
for(int i=0;i<MAXN;i++){
otacs[i]=otaco[i]=i;
vels[i]=velo[i]=1;
}
}
int main()
{
init();
scanf("%d %d",&n, &m);
for(int i=1;i<=m;i++){
int t1,t2;
scanf("%d %d",&t1,&t2);
if(predak(t1,otacs,vels)!=predak(t2,otacs,vels)){
s.insert(mp(t1,t2));
grane.pb(mp(t1,t2));
spoji(t1,t2,otacs,vels);
}else{
//printf(" %d %d\n",t1,t2);
if(s.find(mp(t1,t2))!=s.end())s2.insert(mp(t1,t2));
spoji(t1,t2,otaco,velo);
}
}
for(auto x:s2)fusg.pb(x);
for(auto x:fusg){
int pa=predak(x.first,otaco,velo),pb=predak(x.second,otaco,velo);
printf(" %d %d\n",pa,pb);
if(pa>pb)swap(pa,pb);
s2.insert(mp(pa,pb));
}
for(auto x:grane){
int pa=predak(x.first,otaco,velo),pb=predak(x.second,otaco,velo);
//printf(" %d %d\n",pa,pb);
if(pa>pb)swap(pa,pb);
if(s.find(mp(pa,pb))==s.end())s.insert(mp(pa,pb));
else s2.insert(mp(pa,pb));
}
for(auto x:grane){
int pa=predak(x.first,otaco,velo),pb=predak(x.second,otaco,velo);
if(pa>pb)swap(pa,pb);
if(s2.find(mp(pa,pb))==s2.end())printf("%d %d\n",x.first,x.second);
}
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n, &m);
~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&t1,&t2);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1920 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
2176 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
2048 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
411 ms |
2452 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
842 ms |
3188 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1254 ms |
6000 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2055 ms |
6388 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3137 ms |
7340 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3795 ms |
7344 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4611 ms |
7072 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |