Submission #251988

# Submission time Handle Problem Language Result Execution time Memory
251988 2020-07-23T13:08:48 Z Vladikus004 Birokracija (COCI18_birokracija) C++14
100 / 100
92 ms 26492 KB
#include <bits/stdc++.h>
#define inf 2e9
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 200000 + 3;
int n, sum[N], k[N];
vector <vector <int> > v;

void dfs(int x){
    for (auto u: v[x]){
        dfs(u);
        sum[x] += sum[u] + k[u];
        k[x] += k[u];
    }
    sum[x]++;
    k[x]++;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n;
    v.resize(n);
    for (int i = 1; i < n; i++){
        int x;
        cin >> x;
        --x;
        v[x].push_back(i);
    }
    dfs(0);
    for (int i = 0; i < n; i++)
        cout << sum[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1536 KB Output is correct
2 Correct 11 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4600 KB Output is correct
2 Correct 34 ms 4856 KB Output is correct
3 Correct 23 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 12280 KB Output is correct
2 Correct 66 ms 14420 KB Output is correct
3 Correct 68 ms 26492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 12408 KB Output is correct
2 Correct 71 ms 13432 KB Output is correct
3 Correct 64 ms 15480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 12024 KB Output is correct
2 Correct 69 ms 13688 KB Output is correct
3 Correct 66 ms 17272 KB Output is correct