Submission #83142

#TimeUsernameProblemLanguageResultExecution timeMemory
83142Leonardo_PaesBirokracija (COCI18_birokracija)C++11
100 / 100
209 ms29060 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=2e5+10; int n, m; int in[MAXN], qc[MAXN]; ll resposta[MAXN]; vector <int> graph[MAXN]; int dfs(int u, int f){ for(int v: graph[u]){ if(v!=f){ int qv=dfs(v, u); qc[u]+=qv; resposta[u]+=resposta[v]+qv; } } resposta[u]++; qc[u]++; return qc[u]; } int main(){ cin >> n; for(int i=2;i<=n;++i){ cin >> in[i]; graph[i].push_back(in[i]); graph[in[i]].push_back(i); } dfs(1, 1); for(int i=1;i<=n;++i){ cout << resposta[i] << " \n"[i==n]; } 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...