Submission #782543

#TimeUsernameProblemLanguageResultExecution timeMemory
782543t6twotwoSpring cleaning (CEOI20_cleaning)C++17
18 / 100
1088 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector<vector<int>> adj(N); for (int i = 0; i < N - 1; i++) { int x, y; cin >> x >> y; x--, y--; adj[x].push_back(y); adj[y].push_back(x); } while (Q--) { int D; cin >> D; for (int i = 0; i < D; i++) { int p; cin >> p; p--; adj.push_back({p}); adj[p].push_back(N + i); } int leaves = 0; for (int i = 0; i < N + D; i++) { leaves += adj[i].size() == 1; } if (leaves % 2 == 1) { cout << -1 << "\n"; } else { int ans = 0; auto dfs = [&](auto dfs, int x, int p) -> int { int s = adj[x].size() == 1; for (int y : adj[x]) { if (y == p) { continue; } int t = dfs(dfs, y, x); ans += 2 - t % 2; s += t; } return s; }; dfs(dfs, 0, -1); cout << ans << "\n"; } adj.resize(N); for (int i = 0; i < N; i++) { if (adj[i].back() >= N) { adj[i].pop_back(); } } } return 6/22; }
#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...