Submission #83304

#TimeUsernameProblemLanguageResultExecution timeMemory
83304fredbrBirokracija (COCI18_birokracija)C++17
100 / 100
77 ms28300 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int const maxn = 202020; vector<int> v[maxn]; ll res[maxn]; int solve(int x) { int sz = 1; for (int u : v[x]) { sz += solve(u); res[x] += res[u]; } res[x] += sz; return sz; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int n; cin >> n; for (int i = 2; i <= n; i++) { int a; cin >> a; v[a].push_back(i); } solve(1); for (int i = 1; i <= n; i++) cout << res[i] << " "; cout << "\n"; }
#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...