QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#573725 | #8948. 报复社会 | Akagishigeru | 0 | 55ms | 14092kb | C++14 | 940b | 2024-09-18 19:48:50 | 2024-09-18 19:48:54 |
Judging History
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>>t;
for(int i=1;i<=t;i++) solve(i);
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12044kb
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
result:
wrong answer 1st words differ - expected: 'Bob', found: 'no'
Subtask #2:
score: 0
Wrong Answer
Test #50:
score: 0
Wrong Answer
time: 47ms
memory: 14092kb
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 yes yes no no yes no no yes no no yes no no yes yes no no yes no no yes no yes no no no yes no no yes no no no yes yes no no yes no no no no yes no no yes no no no yes no no no no no yes no yes no yes no no no no no no yes no no no yes no no no no no yes yes no no no no no 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: 55ms
memory: 11900kb
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:
yes yes yes yes no no yes no yes yes no no no yes no yes yes no no no no no yes no no no yes yes no no yes yes no no yes yes yes yes no yes no yes yes yes no no yes no no no no yes no yes no yes no no yes no yes yes yes no no no no no no yes no no yes no no yes yes no no no yes no no yes yes no no n...
result:
wrong answer 1st words differ - expected: 'Alice', found: 'yes'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%