Submission #580128

#TimeUsernameProblemLanguageResultExecution timeMemory
580128NaserBirokracija (COCI18_birokracija)C++17
50 / 100
1096 ms14840 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...