# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241842 | matheo_apd | Birokracija (COCI18_birokracija) | C++14 | 157 ms | 16888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |