답안 #244492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244492 2020-07-04T07:24:08 Z cheeheng Pipes (CEOI15_pipes) C++14
10 / 100
3145 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;
    for(int v: AdjList[u]){
        if(!visited[v]){
            dfs(v, u, d+1);
            dp[u] += dp[v];
        }else if(v != p2 && depth[u] > depth[v]){
            // this is a back edge
            //printf("%d %d is a back edge\n", u, v);
            dp[u] ++;
            dp[v] --;
        }
    }
    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:49:9: warning: unused variable 'temp' [-Wunused-variable]
     int temp = 0;
         ^~~~
pipes.cpp:37: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:41: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 Incorrect 6 ms 2688 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3200 KB Output is correct
2 Incorrect 10 ms 2944 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 10828 KB Output is correct
2 Correct 179 ms 10104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 14328 KB Output is correct
2 Runtime error 384 ms 18544 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 699 ms 25080 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 1047 ms 30448 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 1814 ms 52088 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 2354 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 2762 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 3145 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -