#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
int 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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1108 KB |
Output is correct |
2 |
Correct |
9 ms |
1520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3228 KB |
Output is correct |
2 |
Correct |
28 ms |
3620 KB |
Output is correct |
3 |
Correct |
24 ms |
3864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
8444 KB |
Output is correct |
2 |
Incorrect |
69 ms |
10188 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
8540 KB |
Output is correct |
2 |
Correct |
71 ms |
9932 KB |
Output is correct |
3 |
Incorrect |
71 ms |
10364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
8376 KB |
Output is correct |
2 |
Correct |
81 ms |
9948 KB |
Output is correct |
3 |
Incorrect |
71 ms |
10828 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |