# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1018510 | 2024-07-10T06:24:18 Z | vjudge1 | Birokracija (COCI18_birokracija) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define int long long const int M = 2e5 + 1; int subt[M],ans[M]; vector<int> nei[M]; void dfs(int u) { subt[u]=1; for (int i:nei[u]) { dfs(i); ans[u]+=ans[i]; subt[u]+=subt[i]; } ans[u]+=subt[u]; } int main() { int n; cin>>n; for (int i=2;i<=n;i++) { int u; cin>>u; nei[u].push_back(i); } dfs(1); for (int i=1;i<=n;i++) cout<<ans[i]<<' '; cout<<endl; return 0; }