QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65343#4589. White-Black TreeT3alaadl3k2olyehymn3k#WA 2ms4292kbC++201.0kb2022-11-29 21:42:362022-11-29 21:42:40

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:42:40]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4292kb
  • [2022-11-29 21:42:36]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 69;
vector<int> a;
map<int, vector<int>> th;
int ans = 0;
int dp[N];

int dijkstra(int root) {
    fill(dp, dp + N, 1e9);
    priority_queue<int, vector<int>, greater<>> pq;
    dp[root] = (a[root] == 1);
    pq.push(1);
    while (!pq.empty()) {
        int X = pq.top();
        pq.pop();
        for (auto i: th[X]) {
            if (dp[i] > dp[X] + (a[i] == 1)) {
                dp[i] = dp[X] + (a[i] == 1);
                pq.push(i);
            }
        }
    }
    for (auto i: dp)
        if (i != 1e9)
            ans = max(ans, i);
    return ans;
}

signed main() {
    int n;
    ans = INT_MIN;
    cin >> n;
    a = 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];
    }
//    cout << dijkstra(1) << endl;
    cout << (dijkstra(1) % 2 == 0 ? "First" : "Second") << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4200kb

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: 1ms
memory: 4116kb

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: 4292kb

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 4188kb

input:

2
1
0 0

output:

First

result:

wrong answer 1st lines differ - expected: 'Second', found: 'First'