답안 #244636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244636 2020-07-04T13:17:12 Z tqbfjotld Pipes (CEOI15_pipes) C++14
0 / 100
81 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 root(int a){
    return p[a]==a?a:p[a]=root(p[a]);
}

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[root(b)]>sz[root(a)]) swap(a,b);
            sz[root(a)] += sz[root(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 func(int, int)':
pipes.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
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,&e);
     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:53: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 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 48 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 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 50 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 50 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 61 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 65 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 71 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 81 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 77 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -