QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65374#4589. White-Black TreeT3alaadl3k2olyehymn3kWA 2ms8052kbC++20763b2022-11-29 23:40:362022-11-29 23:40:38

Judging History

This is the latest submission verdict.

  • [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:40:38]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 8052kb
  • [2022-11-29 23:40:36]
  • Submitted

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

input:

7
1 1 1 3 3 3
0 1 1 0 0 0 1

output:

Second

result:

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