QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65341 | #4589. White-Black Tree | T3alaadl3k2olyehymn3k# | WA | 2ms | 3512kb | C++20 | 939b | 2022-11-29 21:30:18 | 2022-11-29 21:30:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<int> a, sz;
map<int, vector<int>> th;
int ans = 0;
void dfs(int u, int p = -1) {
int cool = 0;
int tot1 = 0, tot2 = 0;
for (auto v: th[u]) {
if (v == p)continue;
dfs(v, u);
if (a[v] > tot1) {
tot2 = tot1;
tot1 = a[v];
} else {
tot2 = max(tot2, a[v]);
}
cool = max(cool, a[v]);
}
int tot = tot1 + tot2;
ans = max(ans, a[u] + tot);
a[u] = a[u] + cool;
}
signed main() {
int n;
ans = INT_MIN;
cin >> n;
a = sz = vector<int>(n + 33, 0);
for (int i = 2; i <= n; i++) {
int u;
cin >> u;
th[u].push_back(i);
th[i].push_back(u);
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dfs(1);
cout << (ans % 2 and ans != INT_MIN ? "First" : "Second") << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3512kb
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: 3412kb
input:
5 1 1 2 3 0 1 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
4 1 1 1 1 1 0 1
output:
First
result:
ok single line: 'First'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3312kb
input:
2 1 0 0
output:
Second
result:
ok single line: 'Second'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3316kb
input:
3 1 2 0 1 1
output:
Second
result:
wrong answer 1st lines differ - expected: 'First', found: 'Second'