Submission #237500

#TimeUsernameProblemLanguageResultExecution timeMemory
237500VEGAnnBirokracija (COCI18_birokracija)C++14
100 / 100
105 ms17016 KiB
#include <bits/stdc++.h> #define PB push_back using namespace std; typedef long long ll; const int N = 200100; vector<int> g[N]; int n, siz[N]; ll sum[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i < n; i++){ int x; cin >> x; x--; g[x].PB(i); } for (int v = n - 1; v >= 0; v--){ siz[v] = 1; sum[v] = 0; for (int u : g[v]){ siz[v] += siz[u]; sum[v] += sum[u]; } sum[v] += siz[v]; } for (int i = 0; i < n; i++) cout << sum[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...