#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,0);
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
19496 KB |
Output is correct |
2 |
Correct |
57 ms |
19204 KB |
Output is correct |
3 |
Correct |
81 ms |
21580 KB |
Output is correct |
4 |
Correct |
95 ms |
21580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 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 |
15 ms |
4652 KB |
Output is correct |
8 |
Correct |
250 ms |
22128 KB |
Output is correct |
9 |
Correct |
221 ms |
22092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
22048 KB |
Output is correct |
2 |
Correct |
133 ms |
22060 KB |
Output is correct |
3 |
Correct |
127 ms |
22172 KB |
Output is correct |
4 |
Correct |
128 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
- |