Submission #1018477

#TimeUsernameProblemLanguageResultExecution timeMemory
1018477vjudge1Birokracija (COCI18_birokracija)C++17
100 / 100
65 ms30116 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5+5; ll ans[N], sz[N]; vector<int> child[N]; void dfs(int v) { sz[v] = 1; for(int u : child[v]) { dfs(u); ans[v] += ans[u]; sz[v] += sz[u]; } ans[v] += sz[v]; } int main() { int n; cin >> n; for(int i = 2; i <= n; i ++) { int x; cin >> x; child[x].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...