#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define lun(x) (int)x.size()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<60);
const int inf=(1<<30);
const int nmax=1e5+50;
const ll mod=1e9+7;
using namespace std;
int n,m,q,i,t,tin[nmax],tout[nmax],up[nmax][20],rs[nmax],fw[nmax],ex[nmax],ey[nmax],x,y,z,l[nmax];
vector<int>a[nmax];
void dfs(int x,int p)
{
tin[x]=++t;
up[x][0]=p;
for(int i=1;i<17;i++)up[x][i]=up[up[x][i-1]][i-1];
for(int i=0;i<lun(a[x]);i++)if(a[x][i]!=p)dfs(y,x);
tout[x]=t;
}
void upd(int i,int v)
{
for(;i<=n;i+=i&(-i))fw[i]+=v;
}
int qry(int i)
{
int ans=0;
for(;i>=1;i-=i&(-i))ans+=fw[i];
return ans;
}
int fnd(int x)
{
int cur=qry(tin[x]);
for(int i=16;i>=0;i--)if(qry(tin[up[x][i]])==cur)x=up[x][i];
return x;
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
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;
ex[i]=x,ey[i]=y;
a[x].pb(y);
a[y].pb(x);
}
dfs(1,1);
for(i=1;i<=n;i++)
{
upd(tin[i],1);
upd(tout[i]+1,-1);
rs[i]=1;
}
for(i=1;i<n;i++)if(tin[ex[i]]>tin[ey[i]])swap(ex[i],ey[i]);
while(m--)
{
cin>>i;
x=ex[i],y=ey[i],z=fnd(x);
if(l[i]==-1)
{
upd(tin[y],1);
upd(tout[y]+1,-1);
l[i]=rs[y]=rs[z];
}
else
{
upd(tin[y],-1);
upd(tout[y]+1,1);
rs[z]+=rs[y]-l[i];
l[i]=-1;
}
}
while(q--)
{
cin>>x;
cout<<rs[fnd(x)]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Runtime error |
314 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
344 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
314 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
350 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
307 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |