QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65343 | #4589. White-Black Tree | T3alaadl3k2olyehymn3k# | WA | 2ms | 4292kb | C++20 | 1.0kb | 2022-11-29 21:42:36 | 2022-11-29 21:42:40 |
Judging History
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'