QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114460 | #4589. White-Black Tree | berarchegas# | WA | 2ms | 6392kb | C++17 | 1.2kb | 2023-06-22 04:55:35 | 2023-06-22 04:55:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll INF = 2e18;
vector<int> v[MAXN];
int cor[MAXN], dep[MAXN], qtd[MAXN];
int calcDep(int node) {
for (int x : v[node]) {
dep[node] = max(dep[node], calcDep(x) + 1);
}
return dep[node];
}
int calcQtd(int node) {
qtd[node] = cor[node];
for (int x : v[node]) {
qtd[node] += calcQtd(x);
}
return qtd[node];
}
int dfs(int node) {
if (cor[node]) {
// branco
return dep[node] + qtd[node];
}
else {
// preto
int ans = 0;
for (int x : v[node]) {
ans ^= dfs(x);
}
return ans;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 2; i <= n; i++) {
int p;
cin >> p;
v[p].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> cor[i];
}
calcDep(1);
cout << (dfs(1) ? "First\n" : "Second\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6028kb
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: 2ms
memory: 5780kb
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: 5808kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 2ms
memory: 5952kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: 0
Accepted
time: 2ms
memory: 6316kb
input:
3 1 2 0 1 1
output:
First
result:
ok single line: 'First'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5972kb
input:
3 1 2 1 1 1
output:
First
result:
ok single line: 'First'
Test #7:
score: 0
Accepted
time: 0ms
memory: 6392kb
input:
3 1 1 1 1 1
output:
First
result:
ok single line: 'First'
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 5876kb
input:
3 1 1 0 1 0
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'