#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long
//#include "robots.h"
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e6;
const ll mod = 1e9 + 7;
const int N = 3e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int n, m, q, type[N], L[N], R[N], pos[N], res[N], lst[N], cnt, d[N], from[N], to[N];
vector<int> v[N];
int t[4*N];
void dfs(int nod, int p){
L[nod] = ++cnt;
pos[cnt] = nod;
for(auto it : v[nod]){
if(it == p)continue;
d[it] = d[nod] + 1;
dfs(it, nod);
}
R[nod] = cnt;
}
void build(int v, int l, int r){
if(l == r){
t[v] = R[pos[l]];
return;
}
int mid = (l + r) >> 1;
build(2*v, l, mid);
build(2*v + 1, mid + 1, r);
t[v] = max(t[2*v], t[2*v + 1]);
}
void update(int v, int l, int r, int pos, int val){
if(l == r){
t[v] = val;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid)update(2*v, l, mid, pos, val);else update(2*v + 1, mid + 1, r, pos, val);
t[v] = max(t[2*v], t[2*v + 1]);
}
int find(int v, int l, int r, int pos, int mx){
if(l > pos || t[v] < mx)return 0;
if(l == r)return l;
int mid = (l + r) >> 1;
int x = find(2*v + 1, mid + 1, r, pos, mx);
if(x)return x;
return find(2*v, l, mid, pos, mx);
}
void solve(){
cin >> n >> m >> q;
for(int i = 1; i < n; i++){
cin >> from[i] >> to[i];
v[from[i]].pb(to[i]);
v[to[i]].pb(from[i]);
}
dfs(1, 0);
for(int i = 1; i <= n; i++){
res[i] = 1;
if(d[from[i]] > d[to[i]])swap(from[i], to[i]);
}
build(1, 1, n);
for(int i = 1, e; i <= m; i++){
cin >> e;
if(!type[e]){
res[pos[find(1, 1, n, L[from[e]], R[from[e]])]] += res[to[e]] - lst[e];
update(1, 1, n, L[to[e]], 0);
}else{
res[to[e]] = lst[e] = res[pos[find(1, 1, n, L[from[e]], R[from[e]])]];
update(1, 1, n, L[to[e]], R[to[e]]);
}
type[e] ^= 1;
}
for(int i = 1, x; i <= q; i++){
cin >> x;
cout << res[pos[find(1, 1, n, L[x], R[x])]] << '\n';
}
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//cout << setprecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
70904 KB |
Output is correct |
2 |
Correct |
47 ms |
70904 KB |
Output is correct |
3 |
Correct |
47 ms |
70880 KB |
Output is correct |
4 |
Correct |
47 ms |
70904 KB |
Output is correct |
5 |
Correct |
47 ms |
70904 KB |
Output is correct |
6 |
Correct |
48 ms |
70908 KB |
Output is correct |
7 |
Correct |
61 ms |
71928 KB |
Output is correct |
8 |
Correct |
61 ms |
71928 KB |
Output is correct |
9 |
Correct |
67 ms |
71928 KB |
Output is correct |
10 |
Correct |
257 ms |
81128 KB |
Output is correct |
11 |
Correct |
237 ms |
81016 KB |
Output is correct |
12 |
Correct |
206 ms |
85496 KB |
Output is correct |
13 |
Correct |
178 ms |
81008 KB |
Output is correct |
14 |
Correct |
170 ms |
79992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
147 ms |
82784 KB |
Output is correct |
2 |
Correct |
143 ms |
82684 KB |
Output is correct |
3 |
Correct |
127 ms |
84636 KB |
Output is correct |
4 |
Correct |
125 ms |
84672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
70904 KB |
Output is correct |
2 |
Correct |
48 ms |
70872 KB |
Output is correct |
3 |
Correct |
47 ms |
70904 KB |
Output is correct |
4 |
Correct |
48 ms |
70904 KB |
Output is correct |
5 |
Correct |
48 ms |
70904 KB |
Output is correct |
6 |
Correct |
49 ms |
71040 KB |
Output is correct |
7 |
Correct |
62 ms |
72440 KB |
Output is correct |
8 |
Correct |
231 ms |
86480 KB |
Output is correct |
9 |
Correct |
254 ms |
86392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
248 ms |
86392 KB |
Output is correct |
2 |
Correct |
161 ms |
85792 KB |
Output is correct |
3 |
Correct |
154 ms |
85880 KB |
Output is correct |
4 |
Correct |
153 ms |
85880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
70904 KB |
Output is correct |
2 |
Correct |
47 ms |
70912 KB |
Output is correct |
3 |
Correct |
47 ms |
70904 KB |
Output is correct |
4 |
Correct |
47 ms |
70904 KB |
Output is correct |
5 |
Correct |
48 ms |
70904 KB |
Output is correct |
6 |
Correct |
63 ms |
71928 KB |
Output is correct |
7 |
Correct |
273 ms |
81836 KB |
Output is correct |
8 |
Correct |
231 ms |
86472 KB |
Output is correct |
9 |
Correct |
208 ms |
82160 KB |
Output is correct |
10 |
Correct |
199 ms |
81272 KB |
Output is correct |
11 |
Correct |
175 ms |
84000 KB |
Output is correct |
12 |
Correct |
181 ms |
84088 KB |
Output is correct |
13 |
Correct |
151 ms |
85880 KB |
Output is correct |