Submission #545175

# Submission time Handle Problem Language Result Execution time Memory
545175 2022-04-03T20:13:07 Z MilosMilutinovic Synchronization (JOI13_synchronization) C++14
50 / 100
209 ms 21820 KB
#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=1,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 2728 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 57 ms 19136 KB Output is correct
2 Correct 55 ms 18880 KB Output is correct
3 Correct 77 ms 21152 KB Output is correct
4 Correct 75 ms 21216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 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 16 ms 4608 KB Output is correct
8 Correct 204 ms 21676 KB Output is correct
9 Correct 203 ms 21676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 21736 KB Output is correct
2 Correct 129 ms 21656 KB Output is correct
3 Correct 132 ms 21776 KB Output is correct
4 Correct 122 ms 21820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -