QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65382#4589. White-Black TreeSa3tElSefrWA 4ms5864kbC++201013b2022-11-30 05:45:112022-11-30 05:45:13

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-30 05:45:13]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5864kb
  • [2022-11-30 05:45:11]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

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

#define ll long long
#define ld long double


const int N = 1e5 + 5, lg = 17, mod = 1e9 + 7;

int val[N], col[N], ans, mx[N];
vector<int> adj[N];


void dfs(int node, int par) {
    for(auto i: adj[node]) {
        if(i == par) continue;
        dfs(i, node);
        mx[node] = max(mx[node], mx[i]);
    }
    mx[node]++;

    val[mx[node]] ^= 1;
    if(col[node] == 1) {
        if(val[mx[node]] == 1) ans++;
        else ans--;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    for(int i = 2; i <= n; i++) {
        int u = i, v;
        cin >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

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

    dfs(1, 0);


    if(ans > 0) cout << "First";
    else cout << "Second";


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 5864kb

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

input:

5
1 1 2 3
0 1 1 0 0

output:

Second

result:

ok single line: 'Second'

Test #3:

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

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

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

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

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

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

score: 0
Accepted
time: 4ms
memory: 5776kb

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

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

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

score: 0
Accepted
time: 4ms
memory: 5700kb

input:

3
1 1
0 1 0

output:

First

result:

ok single line: 'First'

Test #9:

score: 0
Accepted
time: 4ms
memory: 5836kb

input:

3
1 1
0 1 1

output:

Second

result:

ok single line: 'Second'

Test #10:

score: -100
Wrong Answer
time: 4ms
memory: 5852kb

input:

4
1 1 2
0 1 1 0

output:

Second

result:

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