답안 #244496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244496 2020-07-04T07:31:48 Z cheeheng Pipes (CEOI15_pipes) C++14
30 / 100
3064 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100005;

vector<int> AdjList[MAX_N];

bitset<MAX_N> visited;

int dp[MAX_N];
int depth[MAX_N];

void dfs(int u, int p2, int d = 0){
    if(visited[u]){return;}
    depth[u] = d;
    visited[u] = true;
    dp[u] = 0;
    int cnt = 0;
    for(int v: AdjList[u]){
        if(!visited[v]){
            dfs(v, u, d+1);
            dp[u] += dp[v];
        }else if( (v != p2 || cnt >= 1) && depth[u] > depth[v]){
            // this is a back edge
            //printf("%d %d is a back edge\n", u, v);

            dp[u] ++;
            dp[v] --;
        }else if(v == p2){cnt ++;}
    }
    if(dp[u] == 0 && p2 != -1){
        printf("%d %d\n", u, p2);
    }
    //printf("dp[%d]=%d\n", u, dp[u]);
}

int main(){
    int N, M;
    scanf("%d%d", &N, &M);

    for(int i = 0; i < M; i ++){
        int a, b;
        scanf("%d%d", &a, &b);
        AdjList[a].push_back(b);
        AdjList[b].push_back(a);
    }

    //memset(dfs_low, -1, sizeof(dfs_low));
    //memset(dfs_num, -1, sizeof(dfs_num));
    //memset(p, -1, sizeof(p));
    int temp = 0;
    for(int i = 1; i <= N; i ++){
        if(!visited[i]){
            dfs(i, -1);
        }
    }

    /*for(int i = 1; i <= N; i ++){
        printf("%d %d\n", i, dp[i]);
    }*/

    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:51:9: warning: unused variable 'temp' [-Wunused-variable]
     int temp = 0;
         ^~~~
pipes.cpp:39: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:43: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 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3200 KB Output is correct
2 Correct 10 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 10744 KB Output is correct
2 Correct 180 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 14312 KB Output is correct
2 Runtime error 398 ms 18664 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 613 ms 25336 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 972 ms 31496 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 1620 ms 53240 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 2229 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 2681 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 3064 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -