Submission #86584

# Submission time Handle Problem Language Result Execution time Memory
86584 2018-11-26T18:35:53 Z rzbt Pipes (CEOI15_pipes) C++14
0 / 100
1372 ms 3964 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;
 
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)){
            grane.pb(mp(t1,t2));
            spoji(t1,t2,otacs,vels);
        }else{
            //printf("   %d %d\n",t1,t2);
            spoji(t1,t2,otaco,velo);
        }
 
    }
    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); ///PAZI
        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); ///PAZI
        if(s2.find(mp(pa,pb))==s2.end() || pa==pb)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 6 ms 2048 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 1920 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 193 ms 2136 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 2372 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 418 ms 3376 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 648 ms 3580 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 875 ms 3856 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1129 ms 3964 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1372 ms 3816 KB Wrong number of edges
2 Halted 0 ms 0 KB -