QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188619#4589. White-Black Tree8BQubeWA 22ms8348kbC++171.5kb2023-09-26 04:53:112023-09-26 04:53:11

Judging History

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

  • [2023-09-26 04:53:11]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:8348kb
  • [2023-09-26 04:53:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back

const int C = 20;
vector<int> G[100005];
int clr[100005], white[100005];

void dfs(int u) {
    if (clr[u] == 1) ++white[u];
    for (int i : G[u])
        dfs(i), white[u] += white[i];
}

int sg(int u, int c) {
    int res = 0, add = 0;
    if (c == 1) {
        if (clr[u] == 0)
            for (int i : G[u])
                res ^= sg(i, c);
        else
            c = 0, add = white[u] - 1;
    }
    if (c == 0) {
        int cnt[C] = {};
        for (int i : G[u]) {
            int val = sg(i, c);
            for (int j = 0; j < C; ++j)
                if (val >> j & 1)
                    ++cnt[j];
        }
        for (int i = C - 1; i >= 0; --i) {
            if (cnt[i] == 1) res |= 1 << i;
            else if (cnt[i] > 1) {
                res |= (1 << (i + 1)) - 1;
                break;
            }
        }
        ++res;
    }
    return res + add;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        int p;
        cin >> p;
        G[p].pb(i);
    }
    for (int i = 1; i <= n; ++i)
        cin >> clr[i];
    dfs(1);
    int res = sg(1, 1);
    if (res) cout << "First\n";
    else cout << "Second\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

5
1 1 2 3
0 1 1 0 0

output:

Second

result:

ok single line: 'Second'

Test #3:

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

input:

4
1 1 1
1 1 0 1

output:

First

result:

ok single line: 'First'

Test #4:

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

input:

2
1
0 0

output:

Second

result:

ok single line: 'Second'

Test #5:

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

input:

3
1 2
0 1 1

output:

First

result:

ok single line: 'First'

Test #6:

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

input:

3
1 2
1 1 1

output:

First

result:

ok single line: 'First'

Test #7:

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

input:

3
1 1
1 1 1

output:

First

result:

ok single line: 'First'

Test #8:

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

input:

3
1 1
0 1 0

output:

First

result:

ok single line: 'First'

Test #9:

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

input:

3
1 1
0 1 1

output:

Second

result:

ok single line: 'Second'

Test #10:

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

input:

4
1 1 2
0 1 1 0

output:

First

result:

ok single line: 'First'

Test #11:

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

input:

4
1 1 1
0 1 1 1

output:

First

result:

ok single line: 'First'

Test #12:

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

input:

4
1 2 3
0 1 0 1

output:

First

result:

ok single line: 'First'

Test #13:

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

input:

5
1 1 2 2
0 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #14:

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

input:

5
1 1 2 2
0 0 1 0 1

output:

Second

result:

ok single line: 'Second'

Test #15:

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

input:

2
1
1 0

output:

First

result:

ok single line: 'First'

Test #16:

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

input:

5
1 1 2 2
0 1 1 0 0

output:

First

result:

ok single line: 'First'

Test #17:

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

input:

5
1 1 1 2
0 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #18:

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

input:

5
1 1 1 2
0 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #19:

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

input:

5
1 1 2 3
0 1 1 1 1

output:

Second

result:

ok single line: 'Second'

Test #20:

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

input:

5
1 1 2 3
0 1 1 1 0

output:

First

result:

ok single line: 'First'

Test #21:

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

input:

6
1 1 1 3 3
0 1 0 1 1 1

output:

Second

result:

ok single line: 'Second'

Test #22:

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

input:

6
1 1 1 3 3
0 1 1 0 1 1

output:

First

result:

ok single line: 'First'

Test #23:

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

input:

8
1 2 3 4 5 6 7
0 1 1 1 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #24:

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

input:

10
1 1 1 2 3 4 5 6 7
0 1 1 1 1 1 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #25:

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

input:

15
1 1 2 2 3 3 4 4 5 5 6 6 7 7
0 1 0 0 1 0 0 0 0 0 0 0 0 0 1

output:

First

result:

ok single line: 'First'

Test #26:

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

input:

2
1
0 1

output:

First

result:

ok single line: 'First'

Test #27:

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

input:

13
1 1 1 2 3 4 5 6 7 8 9 10
0 1 1 1 1 1 1 1 1 1 1 1 1

output:

First

result:

ok single line: 'First'

Test #28:

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

input:

32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

First

result:

ok single line: 'First'

Test #29:

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

input:

33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

First

result:

ok single line: 'First'

Test #30:

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

input:

34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

First

result:

ok single line: 'First'

Test #31:

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

input:

256
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

output:

First

result:

ok single line: 'First'

Test #32:

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

input:

257
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

output:

First

result:

ok single line: 'First'

Test #33:

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

input:

258
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

output:

First

result:

ok single line: 'First'

Test #34:

score: 0
Accepted
time: 22ms
memory: 8348kb

input:

100000
1 2 3 4 4 6 4 7 4 7 8 5 6 5 14 1 17 5 8 10 17 18 13 12 15 11 25 24 3 11 3 21 1 13 30 35 29 6 34 35 41 20 35 36 21 24 37 33 6 37 33 31 8 30 52 43 30 7 25 29 17 12 49 48 30 15 39 10 2 23 44 11 45 17 47 30 73 71 54 36 30 51 37 76 60 9 6 86 60 59 62 16 20 34 13 73 31 60 37 33 58 4 46 66 104 102 1...

output:

First

result:

ok single line: 'First'

Test #35:

score: -100
Wrong Answer
time: 14ms
memory: 8284kb

input:

99999
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 ...

output:

First

result:

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