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>
#define endl '\n'
#define ll long long
using namespace std;
int const maxin = 1e5+6;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a;
cin>>a;
int arr[a+1];
int price[a+1] = {0};
arr[1] = 0;
arr[0] = 0;
for(int i=2;i<a+1;i++)
{
cin>>arr[i];
}
int arr2[a+1];
for(int i=0;i<a+1;i++)
{
arr2[i] = arr[i];
}
sort(arr,arr+a);
for(int i=a;i>=1;i--)
{
bool flag = true ;
int indx = arr2[i];
int cnt = 2;
price[i]+=1;
while(flag == true)
{
if(indx == 0)
flag = false ;
else
{
price[indx]+=cnt;
cnt++;
indx = arr2[indx];
}
}
}
for(int i=1;i<a+1;i++)
{
cout<<price[i]<<" ";
}
return 0;
}
# | 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... |