답안 #170566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170566 2019-12-25T15:57:28 Z rzbt Pipes (CEOI15_pipes) C++14
40 / 100
1640 ms 65536 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];
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;
    }
}

vector<int> niz[MAXN];
bool obidjen[MAXN];
int dfs(int t,int o){
    obidjen[t]=true;
    int vpodst=1;
    for(auto x:niz[t])
        if(x!=o)
            vpodst+=dfs(x,t);
    if(o==0)return vpodst;
    //printf("      %d %d %d\n",t,velo[predak(t,otaco,velo)],vpodst);

    if(velo[predak(t,otaco,velo)]==vpodst)printf("%d %d\n",min(t,o),max(t,o));
    spoji(t,o,otaco,velo);
    return vpodst;

}


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)){
            spoji(t1,t2,otacs,vels);
            niz[t1].pb(t2);
            niz[t2].pb(t1);
        }else{
            //printf("   %d %d\n",t1,t2);
            spoji(t1,t2,otaco,velo);

        }

    }
    for(int i=1;i<=n;i++){
        if(!obidjen[i]){
            //printf("  %d\n",i);
            dfs(i,0);
        }
    }
    /*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:59: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:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&t1,&t2);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4544 KB Output is correct
2 Correct 11 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 4384 KB Output is correct
2 Correct 139 ms 4412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 4576 KB Output is correct
2 Correct 284 ms 4572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 5116 KB Output is correct
2 Runtime error 343 ms 19076 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 513 ms 6520 KB Output is correct
2 Runtime error 460 ms 24824 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 803 ms 6776 KB Output is correct
2 Runtime error 827 ms 40292 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1093 ms 7576 KB Output is correct
2 Runtime error 1018 ms 49016 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1332 ms 7416 KB Output is correct
2 Runtime error 1284 ms 60348 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1640 ms 7312 KB Output is correct
2 Runtime error 1615 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)