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 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 |
---|
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... |