Submission #98119

#TimeUsernameProblemLanguageResultExecution timeMemory
98119dalgerokBirokracija (COCI18_birokracija)C++17
100 / 100
151 ms26240 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, cnt[N]; long long sum[N]; vector < int > g[N]; void dfs(int v){ cnt[v] = 1; for(int to : g[v]){ dfs(to); cnt[v] += cnt[to]; sum[v] += sum[to] + cnt[to]; } sum[v] += 1; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 2; i <= n; i++){ int x; cin >> x; g[x].push_back(i); } dfs(1); for(int i = 1; i <= n; i++){ cout << sum[i] << " "; } }
#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...