Submission #98119

# Submission time Handle Problem Language Result Execution time Memory
98119 2019-02-20T20:10:38 Z dalgerok Birokracija (COCI18_birokracija) C++17
100 / 100
151 ms 26240 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 2e5 + 5;




int n, cnt[N];
long long sum[N];
vector < int > g[N];

void dfs(int v){
    cnt[v] = 1;
    for(int to : g[v]){
        dfs(to);
        cnt[v] += cnt[to];
        sum[v] += sum[to] + cnt[to];
    }
    sum[v] += 1;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 2; i <= n; i++){
        int x;
        cin >> x;
        g[x].push_back(i);
    }
    dfs(1);
    for(int i = 1; i <= n; i++){
        cout << sum[i] << " ";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 6 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 6 ms 5088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5760 KB Output is correct
2 Correct 20 ms 6156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7672 KB Output is correct
2 Correct 45 ms 7928 KB Output is correct
3 Correct 32 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 12216 KB Output is correct
2 Correct 68 ms 14712 KB Output is correct
3 Correct 82 ms 26240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 12340 KB Output is correct
2 Correct 72 ms 13780 KB Output is correct
3 Correct 76 ms 15664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 12088 KB Output is correct
2 Correct 71 ms 13888 KB Output is correct
3 Correct 68 ms 17628 KB Output is correct