QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67703 | #4589. White-Black Tree | karuna# | WA | 4ms | 5896kb | C++17 | 927b | 2022-12-11 06:06:02 | 2022-12-11 06:06:05 |
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]);
}
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");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5720kb
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: 5808kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5648kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 2ms
memory: 5808kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 2ms
memory: 5744kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 3ms
memory: 5652kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: 0
Accepted
time: 4ms
memory: 5728kb
input:
3 1 1 0 1 0
output:
First
result:
ok single line: 'First'
Test #9:
score: 0
Accepted
time: 3ms
memory: 5800kb
input:
3 1 1 0 1 1
output:
Second
result:
ok single line: 'Second'
Test #10:
score: 0
Accepted
time: 3ms
memory: 5720kb
input:
4 1 1 2 0 1 1 0
output:
First
result:
ok single line: 'First'
Test #11:
score: 0
Accepted
time: 0ms
memory: 5896kb
input:
4 1 1 1 0 1 1 1
output:
First
result:
ok single line: 'First'
Test #12:
score: 0
Accepted
time: 3ms
memory: 5800kb
input:
4 1 2 3 0 1 0 1
output:
First
result:
ok single line: 'First'
Test #13:
score: 0
Accepted
time: 4ms
memory: 5804kb
input:
5 1 1 2 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #14:
score: 0
Accepted
time: 3ms
memory: 5832kb
input:
5 1 1 2 2 0 0 1 0 1
output:
Second
result:
ok single line: 'Second'
Test #15:
score: 0
Accepted
time: 3ms
memory: 5720kb
input:
2 1 1 0
output:
First
result:
ok single line: 'First'
Test #16:
score: 0
Accepted
time: 3ms
memory: 5720kb
input:
5 1 1 2 2 0 1 1 0 0
output:
First
result:
ok single line: 'First'
Test #17:
score: 0
Accepted
time: 3ms
memory: 5792kb
input:
5 1 1 1 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #18:
score: 0
Accepted
time: 3ms
memory: 5804kb
input:
5 1 1 1 2 0 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #19:
score: 0
Accepted
time: 3ms
memory: 5808kb
input:
5 1 1 2 3 0 1 1 1 1
output:
Second
result:
ok single line: 'Second'
Test #20:
score: -100
Wrong Answer
time: 3ms
memory: 5720kb
input:
5 1 1 2 3 0 1 1 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'