Submission #294563

# Submission time Handle Problem Language Result Execution time Memory
294563 2020-09-09T05:12:24 Z 7_7_7 Birokracija (COCI18_birokracija) C++17
70 / 100
142 ms 20088 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 7;

int n;
int cnt[N];
int sub[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 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 4 ms 4992 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6144 KB Output is correct
2 Correct 14 ms 6400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 8440 KB Output is correct
2 Correct 30 ms 8448 KB Output is correct
3 Correct 27 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 14692 KB Output is correct
2 Incorrect 73 ms 16504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 126 ms 14788 KB Output is correct
2 Correct 78 ms 15352 KB Output is correct
3 Incorrect 74 ms 17784 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 14456 KB Output is correct
2 Correct 76 ms 15676 KB Output is correct
3 Incorrect 72 ms 20088 KB Output isn't correct