From 96254947699986c59f0dc63d69fd4b76bd3ed43e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Jul 2026 19:08:08 +0200 Subject: Initial commit --- 06_tree_algorithms/subordinates_1674.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 06_tree_algorithms/subordinates_1674.cpp (limited to '06_tree_algorithms/subordinates_1674.cpp') diff --git a/06_tree_algorithms/subordinates_1674.cpp b/06_tree_algorithms/subordinates_1674.cpp new file mode 100644 index 0000000..38982ce --- /dev/null +++ b/06_tree_algorithms/subordinates_1674.cpp @@ -0,0 +1,23 @@ +#include +#include + +int f(const std::vector>& a, std::vector& b, int i) { + for (auto x : a[i]) + b[i] += f(a, b, x) + 1; + return b[i]; +} + +int main() { + int n, x; + std::cin >> n; + std::vector> a(n); + for (int i = 1; i < n; i++) { + std::cin >> x; + a[x-1].push_back(i); + } + std::vector b(n, 0); + f(a, b, 0); + for (auto y : b) + std::cout << y << " "; + std::cout << std::endl; +} -- cgit v1.3