Submission #241842

# Submission time Handle Problem Language Result Execution time Memory
241842 2020-06-25T21:26:07 Z matheo_apd Birokracija (COCI18_birokracija) C++14
70 / 100
157 ms 16888 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define maxn 200005
#define siz first
#define sum second

vector<int> adj[maxn];
int sz_dp[maxn], sum_dp[maxn];
int n;

void dfs(int v){

    if(adj[v].size() == 0){

        sz_dp[v] = sum_dp[v] = 1;
        return;
    }

    for(int i = 0; i < adj[v].size(); i++){

        int u = adj[v][i];

        dfs(u);

        sz_dp[v] += sz_dp[u];
        sum_dp[v] += sum_dp[u];
    }

    sz_dp[v]++;
    sum_dp[v] += sz_dp[v];
}

int main(){

    memset(sum_dp, 0, sizeof sum_dp);
    memset(sz_dp, 0, sizeof sz_dp);
    cin >> n;

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

        int x;
        cin >> x;

        if(i == 1)
            continue;

        adj[x].push_back(i);
    }

    dfs(1);
    
    for(int i = 1; i <= n; i++)
        cout << sum_dp[i] << " ";

    cout << endl;

    return 0;
}

Compilation message

birokracija.cpp: In function 'void dfs(int)':
birokracija.cpp:21:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[v].size(); i++){
                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6528 KB Output is correct
2 Correct 8 ms 6560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6528 KB Output is correct
2 Correct 9 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6528 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 7040 KB Output is correct
2 Correct 23 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8312 KB Output is correct
2 Correct 49 ms 8696 KB Output is correct
3 Correct 51 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 11384 KB Output is correct
2 Incorrect 134 ms 13816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 153 ms 11408 KB Output is correct
2 Correct 139 ms 12920 KB Output is correct
3 Incorrect 141 ms 14840 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 11384 KB Output is correct
2 Correct 132 ms 13176 KB Output is correct
3 Incorrect 132 ms 16888 KB Output isn't correct