QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573722#8948. 报复社会Akagishigeru0 3ms14020kbC++14943b2024-09-18 19:48:202024-09-18 19:48:20

Judging History

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

  • [2024-09-18 19:48:20]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:14020kb
  • [2024-09-18 19:48:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int n,head[maxn],tot,f[maxn],a[maxn],sum[maxn],siz[maxn];
struct edge{
	int t,nxt;
}e[maxn];
void add(int u,int v){
	e[++tot]={v,head[u]};
	head[u]=tot;
}
void dfs(int u){
	siz[u]=1;
	if(!head[u]){
		sum[u]=f[u]=a[u];
		return;
	}
	for(int i=head[u];i;i=e[i].nxt){
		dfs(e[i].t);
		siz[u]+=siz[e[i].t];
		sum[u]+=sum[e[i].t];
	}
	if(siz[u]-1-sum[u]>sum[u]) f[u]=0;
	else if(siz[u]-1-sum[u]<sum[u]) f[u]=1;
	else f[u]=n%2;
	sum[u]+=f[u];
}
void solve(int test){
	cin>>n;
	tot=0;
	for(int i=1;i<=n;i++) head[i]=a[i]=f[i]=sum[i]=0;
	for(int i=2,fa;i<=n;i++){
		scanf("%d",&fa);
		add(fa,i);
	}
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	dfs(1);
	if(f[1]) puts("no");
	else puts("yes");
}
int main(){
	// freopen("alphago.in","r",stdin);
	// freopen("alphago.out","w",stdout);
	int c,t;
	cin>>c>>t;
	for(int i=1;i<=t;i++) solve(i);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 14020kb

input:

1
19
1 2 3 3 2 6 7 7 6 6 6 2 2 2 1 1 1 1
0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 0 0

output:

no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no

result:

wrong answer 1st words differ - expected: 'Bob', found: 'no'

Subtask #2:

score: 0
Wrong Answer

Test #50:

score: 0
Wrong Answer
time: 0ms
memory: 13932kb

input:

10000
49
1 2 2 1 5 5 5 5 5 5 1 12 12 12 12 12 12 1 19 19 19 19 19 19 19 1 27 27 1 1 31 1 33 33 33 33 33 33 33 1 1 1 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1
50
1 2 2 2 2 2 1 8 8 8 1 12 1 1 15 15 15 15 1 1 21 21 21 21 1 26 1 1 29 29...

output:

no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
no
yes
yes
yes
yes
no
no
no
no
no
yes
yes
no
no
yes
no
no
yes

result:

wrong answer 1st words differ - expected: 'Bob', found: 'no'

Subtask #3:

score: 0
Wrong Answer

Test #73:

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

input:

10000
50
1 2 1 4 5 6 5 4 9 4 11 4 1 14 15 16 16 16 15 14 21 21 21 14 14 14 14 14 1 30 30 30 30 30 1 36 37 37 37 36 41 41 41 36 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1
50
1 2 3 4 5 4 7 8 7 4 11 12 11 14 11 16 11 18 11 4 21 4 4 4 3 ...

output:

no
no
no
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
no
no
no
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
no
yes
no
no
no
no
no
no
no
no

result:

wrong answer 1st words differ - expected: 'Alice', found: 'no'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%