QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#309955#8134. LCA Countingucup-team197#WA 1ms3712kbC++201.0kb2024-01-20 23:06:222024-01-20 23:06:23

Judging History

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

  • [2024-01-20 23:06:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2024-01-20 23:06:22]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <array>

using namespace std;

const int N = 2e5 + 3;

int n;
vector<int> adj[N];
int p[N];

int a[N], b[N];

void solve(int u){
    int sum = 0, cnt = 0;
    for(int to: adj[u]){
        solve(to);
        if(!b[to]) continue;
        sum += a[to];
        ++cnt;
        b[u] += b[to];
    }

    if(!adj[u].size()){
        a[u] = 0;
        b[u] = 1;
        return;
    }

    a[u] = sum + (cnt > 1);
    // cout << a[u] << " " << u << " a" << endl;
    // cout << b[u] << " b" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

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

    solve(1);

    for(int i = 0; i < b[1]; ++i){
        if(i <= a[1]){
            cout << (i + (i + 1)) << " ";
        }
        else{
            cout << (a[1]) + i + 1 << " ";
        }
    }
    cout << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7
1 1 2 4 2 2

output:

1 3 5 6 

result:

ok 4 number(s): "1 3 5 6"

Test #2:

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

input:

10
1 1 2 2 1 1 1 2 4

output:

1 3 5 6 7 8 9 

result:

ok 7 numbers

Test #3:

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

input:

10
1 2 2 4 5 6 1 2 4

output:

1 3 5 7 8 

result:

ok 5 number(s): "1 3 5 7 8"

Test #4:

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

input:

10
1 2 3 3 3 5 6 4 9

output:

1 3 4 

result:

ok 3 number(s): "1 3 4"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3712kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 4 1 2 2 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 6 3 1 1 1 2 2 1 1 2 1 2 1 3 1 2 1 1 2 1 1 1 1 1 1 1 4 1 5 1 1 1 1 1 2 1 1 2 1 2 1 2 5 3 1 3 1 1 2 1 2 1 1 3 2 1 6 2 1 2 5 1 1 1 3 2 1 2 1 1 1 1 1...

output:

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 12...

result:

wrong answer 5th numbers differ - expected: '8', found: '9'