QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67707#4589. White-Black Treekaruna#WA 6ms10568kbC++171.2kb2022-12-11 06:34:542022-12-11 06:34:55

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:34:55]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:10568kb
  • [2022-12-11 06:34:54]
  • 提交

answer

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

const int N = 101010;
int n, col[N], dep[N], cnt[N];
vector<int> g[N];
set<int> st[N];

int dfs(int v, int t) {
    int i = v;
    if (col[v]) st[i].insert(dep[v]);
    for (int x : g[v]) {
        dep[x] = dep[v] + 1;
        int j = dfs(x, t | col[v]);
        if (st[i].size() < st[j].size()) {
            swap(i, j);
        }
        for (int x : st[j]) {
            if (t == 0) {
                if (st[i].find(x) == st[i].end()) {
                    st[i].insert(x);
                }
                else st[i].erase(x);
            }
            else {
                while (st[i].find(x) != st[i].end()) {
                    st[i].erase(x);
                    x = x - 1;
                }
                st[i].insert(x);
            }
        }
    }
    return i;
}


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];
    }
    int i = dfs(1, 0);
    cout << (!st[i].empty() ? "First" : "Second");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 10420kb

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: 6ms
memory: 10532kb

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

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

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

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

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

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

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

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

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

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

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

input:

3
1 1
0 1 0

output:

First

result:

ok single line: 'First'

Test #9:

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

input:

3
1 1
0 1 1

output:

Second

result:

ok single line: 'Second'

Test #10:

score: -100
Wrong Answer
time: 2ms
memory: 10460kb

input:

4
1 1 2
0 1 1 0

output:

Second

result:

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