Submission #294565

# Submission time Handle Problem Language Result Execution time Memory
294565 2020-09-09T05:13:19 Z 7_7_7 Birokracija (COCI18_birokracija) C++17
100 / 100
129 ms 29524 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 7;

int n;
int sub[N];
long long cnt[N];
vector<int> g[N];
void dfs(int v, int p){
    sub[v] = 1, cnt[v] = 1;
    for(auto to: g[v]){
        if(to == p) continue;

        dfs(to, v);
        cnt[v] += cnt[to] + sub[to];
        sub[v] += sub[to];
    }
}
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 2; i <= n; i ++){
        int x;
        cin >> x;
        g[x].push_back(i);
        g[i].push_back(x);
    }
    dfs(1, 1);
    for(int i = 1; i <= n; i ++){
        cout << cnt[i] << " ";
    }
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6016 KB Output is correct
2 Correct 12 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 8320 KB Output is correct
2 Correct 30 ms 8344 KB Output is correct
3 Correct 28 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 14340 KB Output is correct
2 Correct 74 ms 15992 KB Output is correct
3 Correct 84 ms 29524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 14288 KB Output is correct
2 Correct 79 ms 14840 KB Output is correct
3 Correct 71 ms 17272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 14128 KB Output is correct
2 Correct 77 ms 15224 KB Output is correct
3 Correct 72 ms 19576 KB Output is correct