QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65375#4589. White-Black TreeT3alaadl3k2olyehymn3kWA 3ms8120kbC++20762b2022-11-29 23:41:022022-11-29 23:41:05

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 23:41:05]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8120kb
  • [2022-11-29 23:41:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 69;
vector<int> G[N];
int h[N], col[N];
map<int, vector<int>> a;

void dfs(int root, int par) {
    h[root] = h[par] + 1;
    if (!col[root]) {
        a[h[root]].push_back(col[root]);
    }
    for (auto i: G[root]) {
        if (i == par)continue;
        dfs(i, root);
    }
}

signed main() {
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int u;
        cin >> u;
        G[u].push_back(i);
        G[i].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        cin >> col[i];
    }
    dfs(1, 0);
    bool flag = 0;
    for (auto i: a)
        flag |= (i.second.size() % 2);
    cout << (flag ? "First" : "Second") << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 8112kb

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: -100
Wrong Answer
time: 0ms
memory: 8120kb

input:

5
1 1 2 3
0 1 1 0 0

output:

First

result:

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