Submission #1018508

#TimeUsernameProblemLanguageResultExecution timeMemory
1018508vjudge1Birokracija (COCI18_birokracija)C++17
70 / 100
99 ms16660 KiB
#include <bits/stdc++.h> using namespace std; 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; }
#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...