Submission #1144015

#TimeUsernameProblemLanguageResultExecution timeMemory
1144015fryingducSynchronization (JOI13_synchronization)C++20
100 / 100
182 ms26284 KiB
// https://github.com/dolphingarlic/CompetitiveProgramming/blob/master/JOI/JOI%2013-synchronisation.cpp #include "bits/stdc++.h" using namespace std; #ifdef duc_debug #include "bits/debug.h" #else #define debug(...) #endif const int maxn = 2e5 + 5; const int LG = 19; int n, m, q; vector<int> g[maxn]; int eu[maxn], ev[maxn]; int tin[maxn], tout[maxn], timer; int stt[maxn], lst[maxn]; int up[maxn][LG + 1], h[maxn]; bool active[maxn]; int bit[maxn]; void update(int i, int val) { for(; i <= timer; i += i & (-i)) { bit[i] += val; } } int get(int i) { int ans = 0; for(; i > 0; i -= i & (-i)) { ans += bit[i]; } return ans; } void pre_dfs(int u, int prev) { tin[u] = ++timer; stt[u] = 1; for(auto v:g[u]) { if(v == prev) continue; h[v] = h[u] + 1; up[v][0] = u; for(int i = 1; i <= LG; ++i) { up[v][i] = up[up[v][i - 1]][i - 1]; } pre_dfs(v, u); } tout[u] = ++timer; } void upd(int u, int d) { update(tin[u], d); update(tout[u], -d); } int find(int u) { for(int i = LG; i >= 0; --i) { if(up[u][i] and get(tin[up[u][i]]) == get(tin[u])) { u = up[u][i]; } } return u; } void solve() { cin >> n >> m >> q; for(int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); eu[i] = u, ev[i] = v; } pre_dfs(1, 0); for(int i = 1; i <= n; ++i) { upd(i, -1); } while(m--) { int e; cin >> e; int u = eu[e], v = ev[e]; if(h[u] > h[v]) swap(u, v); if(!active[e]) { stt[find(u)] += stt[v] - lst[v]; upd(v, 1); } else { stt[v] = lst[v] = stt[find(u)]; upd(v, -1); } active[e] ^= 1; } while(q--) { int u; cin >> u; cout << stt[find(u)] << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#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...