Submission #251987

# Submission time Handle Problem Language Result Execution time Memory
251987 2020-07-23T13:08:22 Z Vladikus004 Birokracija (COCI18_birokracija) C++14
70 / 100
100 ms 16376 KB
#include <bits/stdc++.h>
#define inf 2e9
#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]++;
}

int 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 1 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 6 ms 1408 KB Output is correct
2 Correct 8 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4224 KB Output is correct
2 Correct 23 ms 4608 KB Output is correct
3 Correct 22 ms 5632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 11128 KB Output is correct
2 Incorrect 66 ms 13564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 11124 KB Output is correct
2 Correct 69 ms 12408 KB Output is correct
3 Incorrect 64 ms 14456 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 11000 KB Output is correct
2 Correct 64 ms 12664 KB Output is correct
3 Incorrect 64 ms 16376 KB Output isn't correct