#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 |
1 |
Correct |
1 ms |
320 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 |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
668 KB |
Output is correct |
2 |
Correct |
71 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1648 KB |
Output is correct |
2 |
Correct |
353 ms |
1664 KB |
Output is correct |
3 |
Execution timed out |
1088 ms |
1492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
4172 KB |
Output is correct |
2 |
Execution timed out |
1074 ms |
3916 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
4172 KB |
Output is correct |
2 |
Execution timed out |
1077 ms |
3784 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
4172 KB |
Output is correct |
2 |
Execution timed out |
1076 ms |
3780 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |