답안 #244641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244641 2020-07-04T13:22:16 Z tqbfjotld Pipes (CEOI15_pipes) C++14
0 / 100
87 ms 65540 KB
#include <vector>
#include <cstdio>
using namespace std;
#define MAXN 100005
bool isBridge[MAXN];
int p[MAXN];
int sz[MAXN];
int depth[MAXN];
vector<int> adjl[MAXN];
int p2[MAXN];
int rt[MAXN];

void dfs(int node, int parent){
    for (int x : adjl[node]){
        if (x==parent) continue;
        depth[x] = depth[node]+1;
        rt[x] = rt[node];
        dfs(x,node);
        if(p2[x]!=node){
            isBridge[x] = isBridge[node];
            p2[x] = node;
        }
    }
}



int func(int a, int b){
    if (a==b) return a;
    if (depth[b]<depth[a]) swap(a,b);
    isBridge[b] = false;
    int t = func(a,p[b]);
    p[a] = t;
    p[b] = t;
}

int n,e;

int main(){
    //printf("%d\n",sizeof(isBridge)+sizeof(p)+sizeof(sz)+sizeof(depth)+sizeof(adjl)+sizeof(p2)+sizeof(rt));
    scanf("%d%d",&n,&e);
    for (int x = 1; x<=n; x++){
        isBridge[x] = false;
        p[x] = x;
        sz[x] = 1;
        depth[x] = 0;
        rt[x] = x;
    }
    for (int x = 0; x<e; x++){
        int a,b;
        scanf("%d%d",&a,&b);
        if (rt[a]==rt[b]){
            func(a,b);
        }
        else{
            if (sz[rt[b]]>sz[rt[b]]) swap(a,b);
            sz[rt[a]] += sz[rt[b]];
            adjl[b].push_back(a);
            adjl[a].push_back(b);
            depth[b] = depth[a]+1;
            p2[b] = a;
            p[b] = a;
            rt[b] = rt[a];
            dfs(b,a);
            isBridge[b] = true;
        }
    }
    for (int x = 1; x<=n; x++){
        if (isBridge[x]){
            printf("%d %d\n",x,p2[x]);
        }
    }
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:56:26: warning: self-comparison always evaluates to false [-Wtautological-compare]
             if (sz[rt[b]]>sz[rt[b]]) swap(a,b);
                 ~~~~~~~~~^~~~~~~~~~
pipes.cpp: In function 'int func(int, int)':
pipes.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
pipes.cpp: In function 'int main()':
pipes.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&e);
     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 49 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 47 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 53 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 74 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 79 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 79 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -