This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int x,y,i,n,up[nmax][20],tin[nmax],tout[nmax],t,v,ans[nmax],q,m,fw[nmax],lst[nmax];
vector<int>a[nmax];
vector<pair<int,int> >e;
void dfs(int x,int p)
{
tin[x]=++t;
up[x][0]=p;
for(int i=1;i<20;i++)up[x][i]=up[up[x][i-1]][i-1];
for(int i=0;i<a[x].size();i++)if(a[x][i]!=p)dfs(a[x][i],x);
tout[x]=t+1;
}
void upd(int i,int v)
{
for(;i<=n;i+=i&(-i))fw[i]+=v;
}
int qry(int i)
{
int rs=0;
for(;i>=1;i-=i&(-i))rs+=fw[i];
return rs;
}
int get(int x)
{
int y=qry(tin[x]);
for(int i=19;i>=0;i--)if(qry(tin[up[x][i]])==y)x=up[x][i];
return x;
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m>>q;
for(i=1;i<n;i++)
{
cin>>x>>y;
e.pb({x,y});
a[x].pb(y);
a[y].pb(x);
}
dfs(1,1);
for(i=0;i<n-1;i++)if(tin[e[i].fr]>tin[e[i].sc])swap(e[i].fr,e[i].sc);
for(i=1;i<=n;i++)
{
upd(tin[i],1);
upd(tout[i],-1);
ans[i]=1;
}
while(m--)
{
cin>>i;
x=e[i-1].fr,y=e[i-1].sc,v=get(x);
if(lst[i]==-1)
{
upd(tin[y],1);
upd(tout[y],-1);
ans[y]=lst[i]=ans[v];
}
else
{
upd(tin[y],-1);
upd(tout[y],1);
ans[v]+=ans[y]-lst[i];
lst[i]=-1;
}
}
while(q--)
{
cin>>x;
cout<<ans[get(x)]<<endl;
}
return 0;
}
Compilation message (stderr)
synchronization.cpp: In function 'void dfs(int, int)':
synchronization.cpp:25:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[x].size();i++)if(a[x][i]!=p)dfs(a[x][i],x);
~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |