Submission #86585

# Submission time Handle Problem Language Result Execution time Memory
86585 2018-11-26T18:36:42 Z rzbt Pipes (CEOI15_pipes) C++14
50 / 100
1402 ms 5656 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 5 ms 1920 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 1988 KB Output is correct
2 Correct 120 ms 1992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 2176 KB Output is correct
2 Correct 244 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 2304 KB Output is correct
2 Incorrect 287 ms 3000 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 429 ms 3056 KB Output is correct
2 Correct 369 ms 3132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 673 ms 3064 KB Output is correct
2 Incorrect 708 ms 4968 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 911 ms 3008 KB Output is correct
2 Correct 860 ms 3056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1130 ms 3056 KB Output is correct
2 Correct 1077 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1402 ms 3056 KB Output is correct
2 Incorrect 1354 ms 5656 KB Wrong number of edges