#include<bits/stdc++.h>
#define ld long double
#define pii pair<long long,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define pb push_back
#define f first
#define s second
#define vi vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define ll long long
using namespace std;
const int N=1e5+5;
vector<int>g[N];
vpii edge(N);
int fw[N]{0},pr[N][18]{0},tin[N],tout[N],t=0,d[N]{0},dd[N]{0};
bool vis[N]{0};
void add(int i,int amt){
for(;i<N;i+=i&-i)fw[i]+=amt;
}
int qr(int i,int res=0){
for(;i;i-=i&-i)res+=fw[i];
return res;
}
int get(int u){
int x=qr(tin[u]);
for(int i=17;i>=0;i--)if(qr(pr[u][i])==x)u=pr[u][i];
return u;
}
void dfs(int u,int p){
pr[u][0]=p;tin[u]=++t;
for(int i=1;i<=17;i++)pr[u][i]=pr[pr[u][i-1]][i-1];
for(auto v:g[u]){
if(v==p)continue;
dfs(v,u);
}tout[u]=t;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,q;cin>>n>>m>>q;
for(int i=1;i<=n-1;i++){
cin>>edge[i].f>>edge[i].s;
g[edge[i].f].pb(edge[i].s);
g[edge[i].s].pb(edge[i].f);
}dfs(1,1);
for(int i=1;i<=n;i++)add(tin[i],1),add(tout[i]+1,-1),d[i]=1;
while(m--){
int x;cin>>x;
int u=edge[x].f,v=edge[x].s;
if(v==pr[u][0])swap(u,v);
if(!vis[x]){
d[get(u)]+=d[v]-dd[v];vis[x]=1;
add(tin[v],-1);add(tout[v]+1,1);
}
else {
d[v]=dd[v]=d[get(u)];vis[x]=0;
add(tin[v],1);add(tout[v]+1,-1);
}
}
while(q--){
int x;cin>>x;cout<<d[get(x)]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
20820 KB |
Output is correct |
2 |
Correct |
68 ms |
20680 KB |
Output is correct |
3 |
Correct |
66 ms |
22612 KB |
Output is correct |
4 |
Correct |
68 ms |
22628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5108 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
5312 KB |
Output is correct |
7 |
Correct |
19 ms |
8932 KB |
Output is correct |
8 |
Correct |
178 ms |
24304 KB |
Output is correct |
9 |
Correct |
167 ms |
24344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
24276 KB |
Output is correct |
2 |
Correct |
109 ms |
23660 KB |
Output is correct |
3 |
Correct |
104 ms |
23640 KB |
Output is correct |
4 |
Correct |
109 ms |
23740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4968 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |