#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
vector<int>A(n+5),T(n+5),S(n+5),app(n+5);
for(int i=1;i<n;i++){
cin>>A[i+1];
app[A[i+1]]=1;
}
map<int,int>mp;
for(int i=n;i>=1;i--){
if(!app[i])
T[i]=1;
T[A[i]]+=T[i]+1;
if(mp[A[i]])T[A[i]]--;
mp[A[i]]=1;
S[A[i]]+=S[i]+T[i];
S[i]+=T[i];
}
for(int i=1;i<=n;i++){
cout<<S[i]<<' ';
}
}
//Essa2006 code
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
9 ms |
1548 KB |
Output is correct |
2 |
Correct |
10 ms |
2148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
4816 KB |
Output is correct |
2 |
Correct |
26 ms |
5520 KB |
Output is correct |
3 |
Correct |
28 ms |
5800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
13104 KB |
Output is correct |
2 |
Correct |
69 ms |
15316 KB |
Output is correct |
3 |
Correct |
101 ms |
21044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
13192 KB |
Output is correct |
2 |
Correct |
71 ms |
15020 KB |
Output is correct |
3 |
Correct |
72 ms |
15604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
12964 KB |
Output is correct |
2 |
Correct |
70 ms |
15080 KB |
Output is correct |
3 |
Correct |
68 ms |
15920 KB |
Output is correct |