Submission #238690

# Submission time Handle Problem Language Result Execution time Memory
238690 2020-06-12T11:09:06 Z Vimmer Birokracija (COCI18_birokracija) C++14
100 / 100
142 ms 34808 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 2> a2;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;



set <int> g[N];

ll dp[N], a[N], kol[N];

void dfs(int v)
{
    kol[v] = 1;

    for (auto it : g[v])
    {
        dfs(it);

        kol[v] += kol[it];

        dp[v] += dp[it];
    }

    dp[v] += kol[v];
}
int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;

    cin >> n;

    for (int i = 2; i <= n; i++)
    {
        int x;

        cin >> x;

        g[x].insert(i);
    }

    dfs(1);

    for (int i = 1; i <= n; i++) cout << dp[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 10 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9856 KB Output is correct
2 Correct 10 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 10 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 11136 KB Output is correct
2 Correct 19 ms 11648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 14712 KB Output is correct
2 Correct 38 ms 14848 KB Output is correct
3 Correct 34 ms 15872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 23800 KB Output is correct
2 Correct 80 ms 25464 KB Output is correct
3 Correct 83 ms 34808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 23928 KB Output is correct
2 Correct 89 ms 24568 KB Output is correct
3 Correct 81 ms 26512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 23672 KB Output is correct
2 Correct 85 ms 24696 KB Output is correct
3 Correct 89 ms 28128 KB Output is correct