QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65341#4589. White-Black TreeT3alaadl3k2olyehymn3k#WA 2ms3512kbC++20939b2022-11-29 21:30:182022-11-29 21:30:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-29 21:30:21]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3512kb
  • [2022-11-29 21:30:18]
  • 提交

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'