QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67702#4589. White-Black Treekaruna#WA 3ms5916kbC++17955b2022-12-11 06:03:182022-12-11 06:03:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-11 06:03:19]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5916kb
  • [2022-12-11 06:03:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 101010;
int n, col[N], dp[N];
vector<int> g[N];

void dfs(int v) {
    priority_queue<int> q;
    for (int x : g[v]) {
        dfs(x);
        q.push(dp[x]);
    }
    if (q.empty()) return;
    for (int i = 30; i >= 0; i--) {
        if (!q.empty() && q.top() >> i & 1) {
            int x = q.top(); q.pop();
            q.push(x - (1 << i));
            dp[v] |= (1 << i);
        }
    }
    ++dp[v];
}
int solve(int v) {
    if (col[v]) return dp[v];
    int res = 0;
    for (int x : g[v]) {
        res ^= solve(x);
    }
    return res;
}
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int x; cin >> x;
        g[x].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        cin >> col[i];
    }
    dfs(1);
    int r = solve(1);
    cout << (r ? "First" : "Second");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5600kb

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: 3ms
memory: 5916kb

input:

5
1 1 2 3
0 1 1 0 0

output:

Second

result:

ok single line: 'Second'

Test #3:

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

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

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

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5808kb

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

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

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

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

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

score: -100
Wrong Answer
time: 3ms
memory: 5644kb

input:

3
1 1
0 1 0

output:

Second

result:

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