QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208781#6638. Treelectionxia_mcWA 1ms9848kbC++141.8kb2023-10-09 20:54:522023-10-09 20:54:53

Judging History

你现在查看的是最新测评结果

  • [2023-10-09 20:54:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9848kb
  • [2023-10-09 20:54:52]
  • 提交

answer

// Problem: F - Treelection
// Contest: Virtual Judge - 20231007 杂题选讲(UCup)- PB
// URL: https://vjudge.net/contest/586352#problem/F
// Memory Limit: 254 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<stdio.h>

const int N=1e6+5;
struct dy{
    int v,next;
}edge[N<<1];
int head[N],cnt=1;
void add(int u,int v){
    edge[cnt].v=v;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
int size[N],fa[N],ans,val[N];
bool f[N],put[N];
bool pd(int u,int x){
	if(size[u]<x) return 0;
	if(fa[u]) pd(fa[u],x);
	return 1;
}
void dfs(int u,int dad,int x){
	size[u]=1;fa[u]=dad;
	for(int i=head[u];i;i=edge[i].next){
		int v=edge[i].v;
		if(v!=dad){
			dfs(v,u,x);
			size[u]+=size[v];
			val[u]+=val[v];
		}
	}
	if(val[u]>=x) val[u]-=x;
}
int n;
bool check(int x){
	for(int i=1;i<=n;i++) size[i]=val[i]=0;
	printf("%d %d\n",x,val[1]);
	dfs(1,0,x);
	for(int i=1;i<=n;i++) put[i]=val[i]==1;
	return val[1];
	// for(int i=1;i<=n;i++) f[i]=size[i]>=x?(size[i]==x?pd(i,x):1):0;
	// int s=0;
	// for(int i=1;i<=n;i++) if(f[i]) s++;
	// for(int i=1;i<=n;i++) printf("%d ",f[i]);
	// puts("");
	// if(ans<s){
		// for(int i=1;i<=n;i++) put[i]=f[i],f[i]=0;
		// ans=s;return 1;
	// }
	// for(int i=1;i<=n;i++) f[i]=0;
	// return 0;
}
int main(){
	int T;scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=2,x;i<=n;i++){
			scanf("%d",&x);
			add(x,i);add(i,x);
		}
		// dfs(1,0);
		// for(int i=1;i<=n;i++) size[i]--;
		int l=0,r=n;
		while(l<r){
			printf("%d %d ",l,r);
			int mid=l+r>>1;
			if(!check(mid)) r=mid-1;
			else l=mid;
		}
		for(int i=1;i<=n;i++) printf("%d",put[i]);
		puts("");
		for(int i=1;i<=n;i++) head[i]=fa[i]=size[i]=put[i]=0;
		for(int i=1;i<=cnt;i++) edge[i].v=edge[i].next=0; cnt=1; ans=0;
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9848kb

input:

2
4
1 2 3
5
1 1 2 2

output:

0 4 2 0
0 1 0 0
0000
0 5 2 0
0 1 0 0
00000

result:

wrong answer 1st lines differ - expected: '1100', found: '0 4 2 0'