Submission #362943

#TimeUsernameProblemLanguageResultExecution timeMemory
362943madlogicBirokracija (COCI18_birokracija)C++17
100 / 100
104 ms34872 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<int>> adj(n); for (int i = 0; i < n - 1; i++) { int v; cin >> v; adj[v - 1].push_back(i + 1); } vector<int> res(n); function<pair<int, int>(int)> dfs = [&](int source) { int sum = 0, children = 0; for (int to : adj[source]) { auto [s, c] = dfs(to); sum += s; children += c; } sum += children; ++sum; res[source] = sum; return make_pair(sum, 1 + children); }; dfs(0); for (int i = 0; i < n; i++) { cout << res[i] << " \n"[i == n - 1]; } 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...