// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e5 + 7;
int n, m, q, in[N], out[N], timer, ans[N], lst[N], par[N], up[N][20];
bool active[N];
pair<int, int> e[N];
vector<int> g[N];
void dfs(int u, int p) {
in[u] = ++timer;
for(int i = 1; i < 20; i++) up[u][i] = up[up[u][i - 1]][i - 1];
for(int v : g[u]) {
if(v == p) continue;
par[v] = u;
up[v][0] = u;
dfs(v, u);
}
out[u] = timer;
}
struct BIT {
int n;
vector<int> bit;
BIT() {}
BIT(int n) : n(n) {
bit.resize(n + 1, 0);
}
void update(int u, int x) {
for(; u <= n; u += (u & -u)) bit[u] += x;
}
int get(int u) {
int ans = 0;
for(; u > 0; u -= (u & -u)) ans += bit[u];
return ans;
}
void update(int l, int r, int x) {
update(l, x);
update(r + 1, -x);
}
} bit;
int find(int u) {
for(int i = 19; i >= 0; i--) {
if(bit.get(in[up[u][i]]) == bit.get(in[u])) {
u = up[u][i];
}
}
return u;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> m >> q;
for(int i = 1; i < n; i++) {
int u, v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
e[i] = {u, v};
}
bit = BIT(n);
dfs(1, 0);
for(int i = 1; i <= n; i++) {
bit.update(in[i], out[i], 1);
ans[i] = 1;
}
while(m--) {
int id; cin >> id;
auto [u, v] = e[id];
if(par[v] != u) swap(u, v);
if(!active[id]) {
ans[find(u)] += ans[v] - lst[v];
bit.update(in[v], out[v], -1);
active[id] = 1;
} else {
ans[v] = lst[v] = ans[find(u)];
bit.update(in[v], out[v], 1);
active[id] = 0;
}
}
while(q--) {
int x; cin >> x;
cout << ans[find(x)] << ln;
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
synchronization.cpp: In function 'int main()':
synchronization.cpp:68:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(task ".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:69:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen(task ".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |