Submission #244498

# Submission time Handle Problem Language Result Execution time Memory
244498 2020-07-04T07:33:54 Z cheeheng Pipes (CEOI15_pipes) C++14
40 / 100
552 ms 16632 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, short 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);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1536 KB Output is correct
2 Correct 9 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 5240 KB Output is correct
2 Correct 175 ms 4852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 311 ms 7416 KB Output is correct
2 Correct 375 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 13744 KB Output is correct
2 Runtime error 458 ms 16632 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1792 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1792 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1792 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -