#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 |
1 |
Correct |
1 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5980 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5980 KB |
Output is correct |
2 |
Correct |
2 ms |
6068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5980 KB |
Output is correct |
2 |
Correct |
1 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6744 KB |
Output is correct |
2 |
Correct |
8 ms |
7096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9584 KB |
Output is correct |
2 |
Correct |
21 ms |
8700 KB |
Output is correct |
3 |
Correct |
22 ms |
10072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12332 KB |
Output is correct |
2 |
Correct |
60 ms |
14672 KB |
Output is correct |
3 |
Correct |
63 ms |
28828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12232 KB |
Output is correct |
2 |
Correct |
61 ms |
13656 KB |
Output is correct |
3 |
Correct |
61 ms |
16104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12292 KB |
Output is correct |
2 |
Correct |
56 ms |
13908 KB |
Output is correct |
3 |
Correct |
60 ms |
18520 KB |
Output is correct |