QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#305514 | #4589. White-Black Tree | LeeShoW# | WA | 1ms | 6540kb | C++20 | 944b | 2024-01-15 15:02:06 | 2024-01-15 15:02:07 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<utility>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#define endl '\n'
#define LL long long
const int maxn = 1e5 + 10;
using namespace std;
int par[100005];
int color[100005];//1 wh
//0 black
vector<int>v[100005];
int dp[100005];
int ans[100005];
void dfs1(int now){
for(auto i:v[now]){
dfs1(i);
dp[now]=max(dp[now],dp[i]+1);
}
if(color[now]){
ans[dp[now]]++;
}
}
signed main(){
int n;
cin>>n;
for(int i=2;i<=n;i++){
int o;
cin>>o;
par[i]=o;
v[o].push_back(i);
}
for(int i=1;i<=n;i++){
cin>>color[i];
}
dfs1(1);
bool flag=0;
for(int i=1;i<=n;i++){
if(ans[i]%2==1){
flag=1;
break;
}
}
if(flag){
cout<<"First"<<endl;
}else cout<<"Second"<<endl;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5972kb
input:
7 1 1 1 3 3 3 0 1 1 0 0 0 1
output:
First
result:
ok single line: 'First'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5796kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5976kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6540kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 1ms
memory: 6296kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 1ms
memory: 6224kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 6404kb
input:
3 1 1 0 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'