Submission #886871

#TimeUsernameProblemLanguageResultExecution timeMemory
886871vjudge1Birokracija (COCI18_birokracija)C++17
100 / 100
48 ms23636 KiB
#ifndef Local #pragma GCC optimize("O3,unroll-loops") const int lim=2e5+100; #else const int lim=2e3+100; #endif #include "bits/stdc++.h" using namespace std; #define int int64_t #define pb push_back const int mod=1e9+7; using pii=pair<int,int>; vector<int>v[lim]; int ans[lim]; pii dfs(int node){ int task=1,past=0; for(int j:v[node]){ pii ret=dfs(j); task+=ret.first; past+=ret.second; } ans[node]=task+past; past++; return {ans[node],past}; } inline void solve(){ int n; cin>>n; for(int i=2;i<=n;i++){ int tem; cin>>tem; v[tem].pb(i); } dfs(1); for(int i=1;i<=n;i++){ cout<<ans[i]<<" "; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifdef Local freopen(".in","r",stdin); freopen(".out","w",stdout); #else //freopen("boards.in","r",stdin); //freopen("boards.out","w",stdout); #endif int t=1; //cin>>t; while (t--) { solve(); } }
#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...