QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572105#8948. 报复社会JWRuixi0 0ms0kbC++20786b2024-09-18 12:02:162024-09-18 12:02:16

Judging History

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

  • [2024-09-18 12:02:16]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-09-18 12:02:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=5e5+5;
int cid,n,p[N],c[N];

int tot,hd[N],to[N],nxt[N];
inline void Add(int u,int v){to[++tot]=v;nxt[tot]=hd[u];hd[u]=tot;}
int f[N];
void dfs(int u){
	if(!hd[u]){f[u]=!c[u]?1:-1;return;}
	f[u]=0;
	for(int i=hd[u];i;i=nxt[i]){int v=to[i];dfs(v);f[u]+=f[v];}
	if(f[u])f[u]>0?f[u]++:f[u]--;
	else n&1?f[u]--:f[u]++;
}
inline bool solve(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<=n;i++)hd[i]=0;tot=0;
	for(int i=2;i<=n;i++)Add(p[i],i);
	dfs(1);
	return f[1]>0;
}
int main(){
	freopen("alphago.in","r",stdin);
	freopen("alphago.out","w",stdout);
	int T;scanf("%d%d",&cid,&T);
	while(T--)puts(solve()?"yes":"no");
	return 0;
}

详细

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

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:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #50:

score: 0
Dangerous Syscalls

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:


result:


Subtask #3:

score: 0
Dangerous Syscalls

Test #73:

score: 0
Dangerous Syscalls

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:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%