Submission #237512

# Submission time Handle Problem Language Result Execution time Memory
237512 2020-06-07T06:45:26 Z NONAME Birokracija (COCI18_birokracija) C++17
100 / 100
151 ms 38520 KB
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
using namespace std;

typedef long long ll;
const int N = 2e5 + 10;

ll f[N];
int n, d[N], pr[N];
vector <int> g[N];
set <int> se[N];

void dfs(int v, int pred = -1) {
    d[v] = 1;

    for (int i = 0; i < sz(g[v]); ++i) {
        int to = g[v][i];

        if (to == pred)
            continue;

        dfs(to, v);

        f[v] += f[to];
        d[v] += d[to];
    }

    f[v] += d[v];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;

    for (int i = 0; i < n; ++i)
        pr[i] = i;

    for (int i = 1; i < n; ++i) {
        int x;
        cin >> x;
        x--;

        g[i].pb(x);
        g[x].pb(i);
    }

    dfs(0);

    for (int i = 0; i < n; ++i)
        cout << f[i] << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 13 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 13 ms 14496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 13 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 15488 KB Output is correct
2 Correct 27 ms 15864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 18040 KB Output is correct
2 Correct 39 ms 18040 KB Output is correct
3 Correct 39 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 24496 KB Output is correct
2 Correct 98 ms 26232 KB Output is correct
3 Correct 101 ms 38520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 24568 KB Output is correct
2 Correct 90 ms 25080 KB Output is correct
3 Correct 87 ms 27512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 24312 KB Output is correct
2 Correct 92 ms 25592 KB Output is correct
3 Correct 84 ms 29808 KB Output is correct