Submission #333330

#TimeUsernameProblemLanguageResultExecution timeMemory
333330JovanK26Birokracija (COCI18_birokracija)C++14
100 / 100
132 ms32492 KiB
#include <bits/stdc++.h> using namespace std; long long f[200001]; int sz[200001]; vector<int> v[200001]; void dfs(int cur,int prev) { f[cur]=1; sz[cur]=1; for(auto node : v[cur]) { if(node==prev)continue; dfs(node,cur); f[cur]+=f[node]+sz[node]; sz[cur]+=sz[node]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,x; cin >> n; for(int i=1;i<n;i++) { cin >> x; x--; v[i].push_back(x); v[x].push_back(i); } dfs(0,-1); for(int i=0;i<n;i++) { cout << f[i]<<' '; } 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...