#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 |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
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 |
340 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 |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1756 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
1688 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
5456 KB |
Output is correct |
2 |
Execution timed out |
1096 ms |
2472 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
14740 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
2740 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
590 ms |
14840 KB |
Output is correct |
2 |
Execution timed out |
1083 ms |
3116 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
560 ms |
14416 KB |
Output is correct |
2 |
Execution timed out |
1092 ms |
2940 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |