QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65375 | #4589. White-Black Tree | T3alaadl3k2olyehymn3k | WA | 3ms | 8120kb | C++20 | 762b | 2022-11-29 23:41:02 | 2022-11-29 23:41:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 69;
vector<int> G[N];
int h[N], col[N];
map<int, vector<int>> a;
void dfs(int root, int par) {
h[root] = h[par] + 1;
if (!col[root]) {
a[h[root]].push_back(col[root]);
}
for (auto i: G[root]) {
if (i == par)continue;
dfs(i, root);
}
}
signed main() {
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
int u;
cin >> u;
G[u].push_back(i);
G[i].push_back(u);
}
for (int i = 1; i <= n; i++) {
cin >> col[i];
}
dfs(1, 0);
bool flag = 0;
for (auto i: a)
flag |= (i.second.size() % 2);
cout << (flag ? "First" : "Second") << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 8112kb
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: -100
Wrong Answer
time: 0ms
memory: 8120kb
input:
5 1 1 2 3 0 1 1 0 0
output:
First
result:
wrong answer 1st lines differ - expected: 'Second', found: 'First'