QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#483761#4589. White-Black TreeThirvin#WA 0ms3844kbC++201.2kb2024-07-19 12:19:542024-07-19 12:19:55

Judging History

你现在查看的是最新测评结果

  • [2024-07-19 12:19:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-07-19 12:19:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) signed(size(x))

inline void solve() {
        int n;
        cin >> n;

        vector<vector<int>> adj(n);
        for (int i = 1; i < n; i++) {
                int x;
                cin >> x;
                x--;
                adj[x].push_back(i);
                adj[i].push_back(x);
        }

        vector<int> col(n);
        for (int i = 0; i < n; i++) cin >> col[i];

        vector<int> h(n);
        vector<int> lv(n);
        auto dfs = [&](auto dfs, int x, int lst) -> void {
                if(col[x]) h[lv[x]]++;
                for (auto y : adj[x]) {
                        if (y == lst) continue;
                        lv[y] = lv[x] + 1;
                        dfs(dfs, y, x);
                }
        };
        dfs(dfs, 0, -1);
        for (int i = 0; i < n; i++) {
                if (h[i] & 1) {
                        cout << "First\n";
                        return;
                }
        }
        cout << "Second\n";
        return;
}

signed main() {
        cin.tie(0)->sync_with_stdio(0);
        int t = 1;
        while (t--)
                solve();
        return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3676kb

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: 0ms
memory: 3588kb

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

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

3
1 1
0 1 0

output:

First

result:

ok single line: 'First'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

3
1 1
0 1 1

output:

Second

result:

ok single line: 'Second'

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

input:

4
1 1 2
0 1 1 0

output:

Second

result:

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