QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67702 | #4589. White-Black Tree | karuna# | WA | 3ms | 5916kb | C++17 | 955b | 2022-12-11 06:03:18 | 2022-12-11 06:03:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int n, col[N], dp[N];
vector<int> g[N];
void dfs(int v) {
priority_queue<int> q;
for (int x : g[v]) {
dfs(x);
q.push(dp[x]);
}
if (q.empty()) return;
for (int i = 30; i >= 0; i--) {
if (!q.empty() && q.top() >> i & 1) {
int x = q.top(); q.pop();
q.push(x - (1 << i));
dp[v] |= (1 << i);
}
}
++dp[v];
}
int solve(int v) {
if (col[v]) return dp[v];
int res = 0;
for (int x : g[v]) {
res ^= solve(x);
}
return res;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 2; i <= n; i++) {
int x; cin >> x;
g[x].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> col[i];
}
dfs(1);
int r = solve(1);
cout << (r ? "First" : "Second");
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5600kb
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: 3ms
memory: 5916kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 3ms
memory: 5676kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 3ms
memory: 5808kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 2ms
memory: 5892kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 2ms
memory: 5804kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: -100
Wrong Answer
time: 3ms
memory: 5644kb
input:
3 1 1 0 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'