Submission #885268

#TimeUsernameProblemLanguageResultExecution timeMemory
885268imarnSynchronization (JOI13_synchronization)C++14
100 / 100
299 ms32428 KiB
#include<bits/stdc++.h> #define f first #define s second #define ll long long #define pb push_back #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> using namespace std; const int N=2e5+5; vector<int>g[N]; ll fw[N]{0}; pii e[N]; bool ee[N]{0}; int d[N]{0},dd[N]{0}; int pr[N][18]{0},tin[N]{0},tout[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 t=0; void dfs(int u,int p){ pr[u][0]=p;d[u]=1; for(int i=1;i<=17;i++)pr[u][i]=pr[pr[u][i-1]][i-1]; tin[u]=++t; for(auto v:g[u])if(v!=p)dfs(v,u); tout[u]=++t; } int get(int u){ int x=qr(tin[u]); for(int i=17;i>=0;i--)if(qr(tin[pr[u][i]])==x)u=pr[u][i]; return u; } 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>>e[i].f>>e[i].s,g[e[i].f].pb(e[i].s),g[e[i].s].pb(e[i].f); dfs(1,1);for(int i=1;i<=n;i++)add(tin[i],-1),add(tout[i],1); while(m--){ int x;cin>>x; int u=e[x].f,v=e[x].s; if(tin[u]>tin[v])swap(u,v); if(ee[x]){ d[v]=dd[v]=d[get(u)]; add(tin[v],-1); add(tout[v],1);ee[x]=0; }else { d[get(u)]+=d[v]-dd[v]; add(tin[v],1); add(tout[v],-1);ee[x]=1; } } while(q--){ int x;cin>>x;cout<<d[get(x)]<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...