#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int MOD = 1e9 + 7;
int a[1000000];
int add[1000000];
int b[1000050];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
b[0]=1000000;
for(int i=1;i<n;i++){
cin >> b[i];
b[i]--;
}
for(int t=n-1;t>=0;t--){
add[b[t]]+=add[t]+1;
a[t]++;
a[b[t]]+=a[t]+add[t];
}
for(int i=0;i<n;i++){
cout<<a[i]+add[i]<<' ';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
852 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2116 KB |
Output is correct |
2 |
Correct |
11 ms |
2132 KB |
Output is correct |
3 |
Correct |
13 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
5460 KB |
Output is correct |
2 |
Correct |
49 ms |
5636 KB |
Output is correct |
3 |
Correct |
44 ms |
7076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
5356 KB |
Output is correct |
2 |
Correct |
33 ms |
5612 KB |
Output is correct |
3 |
Correct |
37 ms |
5804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
5268 KB |
Output is correct |
2 |
Correct |
32 ms |
5580 KB |
Output is correct |
3 |
Correct |
32 ms |
6024 KB |
Output is correct |