Submission #86569

# Submission time Handle Problem Language Result Execution time Memory
86569 2018-11-26T15:33:50 Z rzbt Pipes (CEOI15_pipes) C++14
50 / 100
1333 ms 5612 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())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 1920 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 1984 KB Output is correct
2 Correct 112 ms 1984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 2176 KB Output is correct
2 Correct 228 ms 2188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 310 ms 2304 KB Output is correct
2 Incorrect 273 ms 2932 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 403 ms 3056 KB Output is correct
2 Correct 354 ms 3056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 647 ms 3064 KB Output is correct
2 Incorrect 681 ms 5016 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 862 ms 3056 KB Output is correct
2 Correct 825 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1080 ms 3020 KB Output is correct
2 Correct 1029 ms 3056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1333 ms 3056 KB Output is correct
2 Incorrect 1317 ms 5612 KB Wrong number of edges