답안 #170565

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

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);
            grane.pb(mp(t1,t2));
            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:60: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:63: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 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4472 KB Output is correct
2 Correct 9 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 9820 KB Output is correct
2 Correct 145 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 14200 KB Output is correct
2 Correct 297 ms 15992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 409 ms 21328 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 533 ms 27760 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 840 ms 17464 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1133 ms 21784 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1407 ms 26796 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1725 ms 39728 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -