Submission #998257

#TimeUsernameProblemLanguageResultExecution timeMemory
998257fuad27Synchronization (JOI13_synchronization)C++17
0 / 100
47 ms13504 KiB
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int N = 100'010; int n, m, q; vector<pair<int,int>> e; vector<pair<int,int>> vals; vector<int> g[N]; bool state[N]; int dfs(int at, int mx = inf, int p = -1) { // cout << at << " " << mx << endl; int ans=1; for(int ed:g[at]) { int to = (e[ed].first^e[ed].second^at); if(to == p)continue; if(vals[ed].first <= mx) { ans+=dfs(to, min(mx, vals[ed].second), at); } } return ans; } int main () { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> q; for(int i = 1;i<n;i++) { int u, v; cin >> u >> v; e.push_back({u, v}); vals.push_back({inf,-inf}); } for(int i = 0;i<m;i++) { int c; cin >> c; c--; state[c]^=1; if(state[c] == 1 and vals[c].first == inf) { vals[c].first = i; } else vals[c].second = i; } for(int i = 0;i<n-1;i++) { if(vals[i].first == inf)continue; if(vals[i].second == -inf)vals[i].second = inf; g[e[i].first].push_back(i); g[e[i].second].push_back(i); } while(q--) { int a; cin >> a; // dfs(a); cout << dfs(a) << "\n"; // cout << endl; } }
#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...