#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> bool chkmin(T&x,T y){return x>y?x=y,1:0;}
template<typename T> bool chkmax(T&x,T y){return x<y?x=y,1:0;}
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,q,x[200005],y[200005],ans[100005],dep[100005],dfn[100005],dfo[100005],T,fnw[200005],f[100005][20],snc[100005];
vector<int> adj[100005];
bool act[200005];
void dfs(int u,int p){
dfn[u]=++T,ans[u]=1,dep[u]=dep[p]+1,f[u][0]=p;
for(int i=1;i<20;i++) f[u][i]=f[f[u][i-1]][i-1];
for(int v:adj[u]) if(v!=p) dfs(v,u);
dfo[u]=++T;
}
void modify(int x,int v){
for(;x<200005;x+=x&-x) fnw[x]+=v;
}
int query(int x){
int s=0;
for(;x>0;x-=x&-x) s+=fnw[x];
return s;
}
int getf(int x){
for(int i=19;i>=0;i--) if(f[x][i]&&query(f[x][i])==query(x)) x=f[x][i];
return x;
}
int main(){
n=readint(); m=readint(); q=readint();
for(int i=1;i<n;i++){
x[i]=readint(); y[i]=readint();
adj[x[i]].pb(y[i]);
adj[y[i]].pb(x[i]);
}
dfs(1,1);
for(int i=1;i<=n;i++) modify(dfn[i],1),modify(dfo[i],-1);
while(m--){
int i=readint();
if(dep[x[i]]>dep[y[i]])swap(x[i],y[i]);
if(act[i]){
ans[y[i]]=snc[y[i]]=ans[getf(x[i])];
modify(dfn[y[i]],1); modify(dfo[y[i]],-1);
}else{
ans[getf(x[i])]+=ans[y[i]]-snc[y[i]];
modify(dfn[y[i]],-1); modify(dfo[y[i]],1);
}
act[i]=!act[i];
}
while(q--)printf("%d\n",ans[getf(readint())]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
21508 KB |
Output is correct |
2 |
Correct |
71 ms |
21260 KB |
Output is correct |
3 |
Correct |
99 ms |
23304 KB |
Output is correct |
4 |
Correct |
91 ms |
23316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
3 ms |
2900 KB |
Output is correct |
7 |
Correct |
19 ms |
4820 KB |
Output is correct |
8 |
Correct |
260 ms |
24980 KB |
Output is correct |
9 |
Correct |
240 ms |
25084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
248 ms |
24976 KB |
Output is correct |
2 |
Correct |
159 ms |
24340 KB |
Output is correct |
3 |
Correct |
147 ms |
24404 KB |
Output is correct |
4 |
Correct |
136 ms |
24396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |