QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65373#4589. White-Black TreeT3alaadl3k2olyehymn3kWA 5ms8664kbC++20761b2022-11-29 23:39:482022-11-29 23:39:50

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:39:50]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:8664kb
  • [2022-11-29 23:39:48]
  • 提交

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

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

input:

5
1 1 2 3
0 1 1 0 0

output:

Second

result:

ok single line: 'Second'

Test #3:

score: 0
Accepted
time: 5ms
memory: 8276kb

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

score: 0
Accepted
time: 2ms
memory: 8664kb

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

score: 0
Accepted
time: 2ms
memory: 8024kb

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

score: 0
Accepted
time: 2ms
memory: 8056kb

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

score: 0
Accepted
time: 3ms
memory: 7972kb

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

score: 0
Accepted
time: 2ms
memory: 8204kb

input:

3
1 1
0 1 0

output:

First

result:

ok single line: 'First'

Test #9:

score: 0
Accepted
time: 3ms
memory: 8040kb

input:

3
1 1
0 1 1

output:

Second

result:

ok single line: 'Second'

Test #10:

score: -100
Wrong Answer
time: 5ms
memory: 8104kb

input:

4
1 1 2
0 1 1 0

output:

Second

result:

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