QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#483763#4589. White-Black TreeThirvin#WA 0ms3876kbC++201.2kb2024-07-19 12:26:372024-07-19 12:26:37

Judging History

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

  • [2024-07-19 12:26:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3876kb
  • [2024-07-19 12:26:37]
  • 提交

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, 1);
        auto dfs = [&](auto dfs, int x, int lst) -> void {
                for (auto y : adj[x]) {
                        if (y == lst) continue;
                        dfs(dfs, y, x);
                        lv[x] = max(lv[x], lv[y] + 1);
                }
                if(col[x]) h[lv[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: 3612kb

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

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

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

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

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

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

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

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

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

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: 0
Accepted
time: 0ms
memory: 3640kb

input:

4
1 1 2
0 1 1 0

output:

First

result:

ok single line: 'First'

Test #11:

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

input:

4
1 1 1
0 1 1 1

output:

First

result:

ok single line: 'First'

Test #12:

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

input:

4
1 2 3
0 1 0 1

output:

First

result:

ok single line: 'First'

Test #13:

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

input:

5
1 1 2 2
0 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #14:

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

input:

5
1 1 2 2
0 0 1 0 1

output:

Second

result:

ok single line: 'Second'

Test #15:

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

input:

2
1
1 0

output:

Second

result:

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