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 int long long
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
vector<int>A(n+5);
vector<bool>V(n+5);
for(int i=1;i<n;i++){
int a;
cin>>a;
A[i+1]=a;
V[a]=1;
}
map<int,ll>mp;
for(int i=1;i<=n;i++){
int res=1;
int ind=i;
while(true){
mp[ind]+=res;
res++;
if(ind==1)
break;
ind=A[ind];
}
}
for(int i=1;i<=n;i++){
cout<<mp[i]<<' ';
}
}
# | 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... |