QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67707 | #4589. White-Black Tree | karuna# | WA | 6ms | 10568kb | C++17 | 1.2kb | 2022-12-11 06:34:54 | 2022-12-11 06:34:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int n, col[N], dep[N], cnt[N];
vector<int> g[N];
set<int> st[N];
int dfs(int v, int t) {
int i = v;
if (col[v]) st[i].insert(dep[v]);
for (int x : g[v]) {
dep[x] = dep[v] + 1;
int j = dfs(x, t | col[v]);
if (st[i].size() < st[j].size()) {
swap(i, j);
}
for (int x : st[j]) {
if (t == 0) {
if (st[i].find(x) == st[i].end()) {
st[i].insert(x);
}
else st[i].erase(x);
}
else {
while (st[i].find(x) != st[i].end()) {
st[i].erase(x);
x = x - 1;
}
st[i].insert(x);
}
}
}
return i;
}
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];
}
int i = dfs(1, 0);
cout << (!st[i].empty() ? "First" : "Second");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10420kb
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: 6ms
memory: 10532kb
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: 10452kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 0ms
memory: 10412kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 2ms
memory: 10476kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 2ms
memory: 10468kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 1ms
memory: 10568kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: 0
Accepted
time: 3ms
memory: 10548kb
input:
3 1 1 0 1 0
output:
First
result:
ok single line: 'First'
Test #9:
score: 0
Accepted
time: 0ms
memory: 10468kb
input:
3 1 1 0 1 1
output:
Second
result:
ok single line: 'Second'
Test #10:
score: -100
Wrong Answer
time: 2ms
memory: 10460kb
input:
4 1 1 2 0 1 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'