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 int long long
int const N=2e5+5;
int const mod=1e9+7;
vector<int> child[N];
int pay[N],sz[N];
void dfs(int node){
sz[node]=1;
for(int i:child[node]){
dfs(i);
pay[node]+=pay[i];
sz[node]+=sz[i];
}
pay[node]+=sz[node];
}
signed main(){
int n;
cin>>n;
for(int i=2;i<=n;i++){
int p;
cin>>p;
child[p].push_back(i);
}
dfs(1);
for(int i=1;i<=n;i++)
cout<<pay[i]<<' ';
cout<<endl;
return 0;
}
# | 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... |