QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65360#4589. White-Black TreeSa3tElSefrWA 4ms5780kbC++201.1kb2022-11-29 22:24:362022-11-29 22:24:37

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 22:24:37]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5780kb
  • [2022-11-29 22:24:36]
  • 提交

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;


vector<int> adj[N];

int sz[N];

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

int xr = 0, col[N];

void dfsAns(int node, int par) {
    if(col[node] == 1) {
        // cout << node << ' ' << col[node] << '\n';
        xr ^= (sz[node] - 1);
        return;
    }

    for(auto i: adj[node]) {
        if(i == par) continue;
        dfsAns(i, node);
    }
}

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);
    dfsAns(1, 0);

    if(xr == 0) cout << "Second";
    else cout << "First";

    return 0;
}

詳細信息

Test #1:

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

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: 4ms
memory: 5664kb

input:

5
1 1 2 3
0 1 1 0 0

output:

Second

result:

ok single line: 'Second'

Test #3:

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

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

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

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

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

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

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

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

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

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

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

input:

3
1 1
0 1 0

output:

Second

result:

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