#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define int long long
#define log 16
#define fi first
#define se second
typedef pair<int, int> ii;
int n, m, par[log + 2][N], dep[N], tin[N], tout[N], tim, bit[4 * N], lazy[4 * N], res[N], lst[N], q, vs[N];
ii eg[N];
vector<int> adj[N];
void add(int id, int l, int r, int val){
bit[id] += val * (r - l + 1);
lazy[id] += val;
}
void down(int id, int l, int r){
if (l == r) return;
int mid = (l + r) >> 1;
add(id * 2, l, mid, lazy[id]);
add(id * 2 + 1, mid + 1, r, lazy[id]);
}
void ud(int id, int l, int r, int u, int v, int val){
if (u > r || l > v) return;
if (l >= u && r <= v){
add(id, l, r, val);
return;
}
down(id, l, r);
int mid = (l + r) >> 1;
ud(id * 2, l, mid, u, v, val);
ud(id * 2 + 1, mid + 1, r, u, v, val);
bit[id] = bit[id * 2] + bit[id * 2 + 1];
}
int get(int id, int l, int r, int pos){
if (r < pos || l > pos) return 0;
if (l == r) return bit[id];
down(id, l, r);
int mid = (l + r) >> 1;
return get(id * 2, l, mid, pos) + get(id * 2 + 1, mid + 1, r, pos);
}
void dfs(int u, int p){
par[0][u] = p;
dep[u] = dep[p] + 1;
tin[u] = ++tim;
res[u] = 1;
for (auto x : adj[u]){
if (x == p) continue;
dfs(x, u);
}
tout[u] = tim;
}
int go(int u){
for (int k = log; k >= 0; k--){
if (!par[k][u]) continue;
if (get(1, 1, n, tin[u]) - get(1, 1, n, tin[par[k][u]]) == dep[u] - dep[par[k][u]]){
u = par[k][u];
}
}
return u;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m >> q;
for (int i = 1; i <= n - 1; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
eg[i] = {u, v};
}
dfs(1, 0);
for (int k = 1; k <= log; k++){
for (int i = 1; i <= n; i++){
par[k][i] = par[k - 1][par[k - 1][i]];
}
}
for (int i = 1; i <= n - 1; i++){
if (dep[eg[i].fi] > dep[eg[i].se]) swap(eg[i].fi, eg[i].se);
}
for (int i = 1; i <= m; i++){
int u;
cin >> u;
if (vs[u]){
res[eg[u].se] = lst[eg[u].se] = res[go(eg[u].se)];
ud(1, 1, n, tin[eg[u].se], tout[eg[u].se], -1);
}
else{
res[go(eg[u].fi)] += res[eg[u].se] - lst[eg[u].se];
ud(1, 1, n, tin[eg[u].se], tout[eg[u].se], 1);
}
vs[u] ^= 1;
}
for (int i = 1; i <= n; i++){
res[i] = res[go(i)];
}
while (q--){
int u;
cin >> u;
cout << res[u] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
23176 KB |
Output is correct |
2 |
Incorrect |
4 ms |
23120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
674 ms |
37060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
23120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1325 ms |
40116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
23120 KB |
Output is correct |
2 |
Incorrect |
3 ms |
23120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |