#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 {
last[v] = res[v];
res[v] = res[p];
update(1, 1, 2 * n, st[v], 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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
9796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
143 ms |
16384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
9796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
232 ms |
18432 KB |
Execution killed because of forbidden syscall writev (20) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9796 KB |
Output is correct |
2 |
Incorrect |
2 ms |
9796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |