Submission #251988

#TimeUsernameProblemLanguageResultExecution timeMemory
251988Vladikus004Birokracija (COCI18_birokracija)C++14
100 / 100
92 ms26492 KiB
#include <bits/stdc++.h> #define inf 2e9 #define int long long #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; const int N = 200000 + 3; int n, sum[N], k[N]; vector <vector <int> > v; void dfs(int x){ for (auto u: v[x]){ dfs(u); sum[x] += sum[u] + k[u]; k[x] += k[u]; } sum[x]++; k[x]++; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LOCAL cin >> n; v.resize(n); for (int i = 1; i < n; i++){ int x; cin >> x; --x; v[x].push_back(i); } dfs(0); for (int i = 0; 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...