Submission #900482

#TimeUsernameProblemLanguageResultExecution timeMemory
900482Trisanu_DasSpring cleaning (CEOI20_cleaning)C++17
34 / 100
1064 ms15356 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> adj[100002]; int leaf[100002]; int dp[100002]; ll ans = 0; void dfs(int x, int p){ dp[x] = leaf[x]; for(auto u : adj[x]){ if(u != p){ dfs(u, x); dp[x] += dp[u]; } } if(x == 1){ if(adj[x].size() == 1 && leaf[x] == 0){ if(dp[x] == 1){ ans++; return; } else { ans = -1LL; return; } } if(dp[x]%2) { ans = -1LL; return; } else{ ans += dp[x]; return; } } 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); } for(int i=1;i<=q;i++){ fill(leaf, leaf + 30002, 0); int d; scanf("%d", &d); for(int i=1;i<=d;i++){ int l; scanf("%d", &l); leaf[l]++; } ans = 0; dfs(1, -1); printf("%lld\n", ans); } }

Compilation message (stderr)

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