제출 #342487

#제출 시각아이디문제언어결과실행 시간메모리
342487benedict0724Spring cleaning (CEOI20_cleaning)C++17
0 / 100
1096 ms7916 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> adj[100002]; int leaf[100002]; int deg[100002]; int par[100002]; bool check[100002]; bool pos; int dp[100002]; ll ans = 0; void dfs(int x, int p){ dp[x] = leaf[x]; for(auto u : adj[x]){ if(u != p){ par[u] = x; dfs(u, x); dp[x] += dp[u]; } } if(dp[x] == 0){ dp[x] = 1; return; } if(dp[x]%2){ ans += dp[x]; dp[x] = 1; return; } ans += dp[x]; dp[x] = 2; } int main() { int n, q; scanf("%d %d", &n, &q); for(int i=1;i<n;i++){ int s, e; scanf("%d %d", &s, &e); adj[s].push_back(e); adj[e].push_back(s); deg[s]++; deg[e]++; } pos = true; for(int i=1;i<=n;i++){ if(deg[i] == 1) pos = !pos; } dfs(1, -1); for(int i=1;i<=q;i++){ int d; scanf("%d", &d); vector<int> v; for(int i=1;i<=d;i++){ int k; scanf("%d", &k); check[k] = false; bool change = true; if(deg[k] == 1){ ans++; deg[k]++; change = false; check[k] = true; } else pos = !pos; v.push_back(k); if(change) while(k != 1){ if(dp[k] == 1){ ans++; dp[k] = 2; } else{ ans--; dp[k] = 1; } k = par[k]; } } if(pos) printf("%lld\n", ans); else printf("-1\n"); for(auto k : v){ if(check[k]){ deg[k]--; ans--; } else{ while(k != 1){ if(dp[k] == 1){ ans++; dp[k] = 2; } else{ ans--; dp[k] = 1; } k = par[k]; } } pos = !pos; } } }

컴파일 시 표준 에러 (stderr) 메시지

cleaning.cpp: In function 'int main()':
cleaning.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
cleaning.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         scanf("%d %d", &s, &e);
      |         ~~~~~^~~~~~~~~~~~~~~~~
cleaning.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |         scanf("%d", &d);
      |         ~~~~~^~~~~~~~~~
cleaning.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |             scanf("%d", &k);
      |             ~~~~~^~~~~~~~~~
#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...