# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580126 | 2022-06-20T15:52:55 Z | Naser | Karte (COCI18_karte) | C++17 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #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]<<' '; } }