Submission #40067

#TimeUsernameProblemLanguageResultExecution timeMemory
40067minkankSynchronization (JOI13_synchronization)C++14
100 / 100
851 ms18432 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; #define st first #define nd second const int N = 1e5 + 5; int n, m, q, h[N], st[N], en[N], cur, last[N], res[N], it[N * 8]; bool check[2 * N]; vector<int> G[N]; vector<ii> E; #define mid ((l + r) / 2) void update(int node, int l, int r, int p, int val) { if(p > r || p < l) return; if(l == r) { it[node] += val; return; } update(node << 1, l, mid, p, val); update(node << 1 | 1, mid + 1, r, p, val); int Left = it[node << 1], Right = it[node << 1 | 1]; if(en[Left] > en[Right]) it[node] = Left; else it[node] = Right; } int find(int node, int l, int r, int p, int val) { if(p < l) return 0; if(r <= p && en[it[node]] < en[val]) return 0; if(l == r) return it[node]; int Right = find(node << 1 | 1, mid + 1, r, p, val); if(Right) return Right; return find(node << 1, l, mid, p, val); } #undef mid void dfs(int u, int p) { st[u] = ++cur; for(int v: G[u]) { if(v == p) continue; h[v] = h[u] + 1; dfs(v, u); } en[u] = ++cur; } int main() { //ios::sync_with_stdio(false); cin.tie(0); 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); E.push_back(ii(u, v)); } dfs(1, 1); for(int i = 1; i <= n; ++i) res[i] = 1, update(1, 1, 2 * n, st[i], i); for(int i = 1; i <= m; ++i) { int id; cin >> id; id--; int u, v; u = E[id].st; v = E[id].nd; if(h[u] > h[v]) swap(u, v); int p = find(1, 1, 2 * n, st[u], u); if(!check[id]) { res[p] += res[v] - last[v]; update(1, 1, 2 * n, st[v], -v); } else { res[v] = res[p]; update(1, 1, 2 * n, st[v], v); } last[v] = res[v]; check[id] ^= 1; } for(int i = 1; i <= q; ++i) { int u; cin >> u; cout << res[find(1, 1, 2 * n, st[u], u)] << '\n'; } }
#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...