답안 #244500

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

const int MAX_N = 30005;

vector<short> AdjList[MAX_N];

bitset<MAX_N> visited;

short dp[MAX_N];
short depth[MAX_N];

void dfs(short u, short p2){
    if(visited[u]){return;}
    if(p2 == -1){depth[u] = 0;}
    visited[u] = true;
    dp[u] = 0;
    int cnt = 0;
    for(int v: AdjList[u]){
        if(!visited[v]){
            depth[v] = depth[u]+1;
            dfs(v, u);
            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:52:9: warning: unused variable 'temp' [-Wunused-variable]
     int temp = 0;
         ^~~~
pipes.cpp:40: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:44: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 5 ms 1024 KB Output is correct
2 Correct 5 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1536 KB Output is correct
2 Correct 9 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 5368 KB Output is correct
2 Correct 165 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 7544 KB Output is correct
2 Correct 376 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 583 ms 13664 KB Output is correct
2 Correct 450 ms 11768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -