Submission #244500

#TimeUsernameProblemLanguageResultExecution timeMemory
244500cheehengPipes (CEOI15_pipes)C++14
50 / 100
583 ms13664 KiB
#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 (stderr)

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);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...