#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=4e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<62);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
ll n,x,y,m,q,bit[N],in[N],out[N],ti=1,lca[N][21],cd,ans[N],last[N],B[N];
vector<pll> edge;
vector<ll> v[N];
void DFS(ll nd,ll pa){
lca[nd][0]=pa;
in[nd]=ti++;
ans[nd]=1;
for(ll i=1;i<=20&&lca[nd][i-1];i++)lca[nd][i]=lca[lca[nd][i-1]][i-1];
for(auto i:v[nd]){
if(i==pa)continue;
DFS(i,nd);
}
out[nd]=ti;
}
void mod(ll id,ll dx){
while(id<N)bit[id]+=dx,id+=(id&-id);
}
ll query(ll id){
ll tmp=0;while(id)tmp+=bit[id],id-=(id&-id);return tmp;
}
ll find(ll id){
ll tmp=id;
for(ll i=20;i>=0;i--)if(lca[tmp][i]&&query(in[lca[tmp][i]])==query(in[id]))tmp=lca[tmp][i];
return tmp;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m>>q;
REP(i,n-1){
cin>>x>>y;
edge.pb(mp(x,y));
v[x].pb(y);v[y].pb(x);
}
DFS(1,0);
REP1(i,n)mod(in[i],-1),mod(out[i],1);
REP(i,m){
cin>>cd;
y=edge[cd-1].Y;x=edge[cd-1].X;
if(lca[y][0]==x)swap(x,y);
if(B[cd-1]){
ans[x]=last[x]=ans[find(y)];
mod(in[x],-1),mod(out[x],1);
}else{
ans[find(y)]+=ans[x]-last[x];
mod(in[x],1),mod(out[x],-1);
}
B[cd-1]=1-B[cd-1];
}
while(q--)cin>>x,cout<<ans[find(x)]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9848 KB |
Output is correct |
2 |
Correct |
10 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9848 KB |
Output is correct |
4 |
Correct |
10 ms |
9848 KB |
Output is correct |
5 |
Correct |
10 ms |
9848 KB |
Output is correct |
6 |
Correct |
11 ms |
10104 KB |
Output is correct |
7 |
Correct |
23 ms |
12404 KB |
Output is correct |
8 |
Correct |
22 ms |
12404 KB |
Output is correct |
9 |
Correct |
24 ms |
12532 KB |
Output is correct |
10 |
Correct |
247 ms |
36196 KB |
Output is correct |
11 |
Correct |
255 ms |
36196 KB |
Output is correct |
12 |
Correct |
327 ms |
40292 KB |
Output is correct |
13 |
Correct |
145 ms |
36456 KB |
Output is correct |
14 |
Correct |
175 ms |
35428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
37860 KB |
Output is correct |
2 |
Correct |
135 ms |
37392 KB |
Output is correct |
3 |
Correct |
147 ms |
39656 KB |
Output is correct |
4 |
Correct |
159 ms |
39652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9848 KB |
Output is correct |
2 |
Correct |
10 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9848 KB |
Output is correct |
4 |
Correct |
10 ms |
9848 KB |
Output is correct |
5 |
Correct |
10 ms |
9848 KB |
Output is correct |
6 |
Correct |
14 ms |
10104 KB |
Output is correct |
7 |
Correct |
31 ms |
12916 KB |
Output is correct |
8 |
Correct |
398 ms |
40752 KB |
Output is correct |
9 |
Correct |
382 ms |
40548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
401 ms |
40676 KB |
Output is correct |
2 |
Correct |
227 ms |
40036 KB |
Output is correct |
3 |
Correct |
224 ms |
40292 KB |
Output is correct |
4 |
Correct |
217 ms |
40288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9848 KB |
Output is correct |
2 |
Correct |
10 ms |
9848 KB |
Output is correct |
3 |
Correct |
10 ms |
9848 KB |
Output is correct |
4 |
Correct |
10 ms |
9848 KB |
Output is correct |
5 |
Correct |
12 ms |
10104 KB |
Output is correct |
6 |
Correct |
26 ms |
12532 KB |
Output is correct |
7 |
Correct |
294 ms |
36556 KB |
Output is correct |
8 |
Correct |
400 ms |
40548 KB |
Output is correct |
9 |
Correct |
163 ms |
36964 KB |
Output is correct |
10 |
Correct |
197 ms |
36196 KB |
Output is correct |
11 |
Correct |
160 ms |
38500 KB |
Output is correct |
12 |
Correct |
153 ms |
38372 KB |
Output is correct |
13 |
Correct |
219 ms |
40292 KB |
Output is correct |