Submission #237500

# Submission time Handle Problem Language Result Execution time Memory
237500 2020-06-07T06:18:23 Z VEGAnn Birokracija (COCI18_birokracija) C++14
100 / 100
105 ms 17016 KB
#include <bits/stdc++.h>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 200100;
vector<int> g[N];
int n, siz[N];
ll sum[N];

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

    cin >> n;

    for (int i = 1; i < n; i++){
        int x; cin >> x; x--;

        g[x].PB(i);
    }

    for (int v = n - 1; v >= 0; v--){
        siz[v] = 1;
        sum[v] = 0;

        for (int u : g[v]){
            siz[v] += siz[u];
            sum[v] += sum[u];
        }

        sum[v] += siz[v];
    }

    for (int i = 0; i < n; i++)
        cout << sum[i] << " ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5760 KB Output is correct
2 Correct 14 ms 6016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 7584 KB Output is correct
2 Correct 28 ms 7936 KB Output is correct
3 Correct 35 ms 8056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 12280 KB Output is correct
2 Correct 69 ms 13560 KB Output is correct
3 Correct 64 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 12152 KB Output is correct
2 Correct 69 ms 13304 KB Output is correct
3 Correct 70 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 12024 KB Output is correct
2 Correct 66 ms 13176 KB Output is correct
3 Correct 64 ms 13944 KB Output is correct