답안 #241843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241843 2020-06-25T21:37:31 Z matheo_apd Birokracija (COCI18_birokracija) C++17
70 / 100
170 ms 15608 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++){
                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6656 KB Output is correct
2 Correct 9 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6656 KB Output is correct
2 Correct 10 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6656 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6784 KB Output is correct
2 Correct 23 ms 7296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 7928 KB Output is correct
2 Correct 52 ms 8312 KB Output is correct
3 Correct 54 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 10232 KB Output is correct
2 Incorrect 133 ms 12664 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 10232 KB Output is correct
2 Correct 137 ms 11768 KB Output is correct
3 Incorrect 131 ms 13688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 10172 KB Output is correct
2 Correct 134 ms 11896 KB Output is correct
3 Incorrect 133 ms 15608 KB Output isn't correct