Submission #1018562

#TimeUsernameProblemLanguageResultExecution timeMemory
1018562vjudge1Birokracija (COCI18_birokracija)C++17
100 / 100
63 ms28828 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int const N=2e5+5; int const mod=1e9+7; vector<int> child[N]; int pay[N],sz[N]; void dfs(int node){ sz[node]=1; for(int i:child[node]){ dfs(i); pay[node]+=pay[i]; sz[node]+=sz[i]; } pay[node]+=sz[node]; } signed main(){ int n; cin>>n; for(int i=2;i<=n;i++){ int p; cin>>p; child[p].push_back(i); } dfs(1); for(int i=1;i<=n;i++) cout<<pay[i]<<' '; cout<<endl; return 0; }
#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...