#include #include #include #include #include #include template inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } struct range { using itr = int64_t; struct iterator { itr i; constexpr iterator(itr i_) noexcept : i(i_) { } constexpr void operator ++ () noexcept { ++i; } constexpr itr operator * () const noexcept { return i; } constexpr bool operator != (iterator x) const noexcept { return i != x.i; } }; const iterator l, r; constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { } constexpr iterator begin() const noexcept { return l; } constexpr iterator end() const noexcept { return r; } }; struct revrange { using itr = int64_t; struct iterator { itr i; constexpr iterator(itr i_) noexcept : i(i_) { } constexpr void operator ++ () noexcept { --i; } constexpr itr operator * () const noexcept { return i; } constexpr bool operator != (iterator x) const noexcept { return i != x.i; } }; const iterator l, r; constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { } constexpr iterator begin() const noexcept { return r; } constexpr iterator end() const noexcept { return l; } }; using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; template struct fix_point: private T { explicit constexpr fix_point(T &&func): T(std::forward(func)) { } template constexpr decltype(auto) operator () (Args &&... args) const { return T::operator()(*this, std::forward(args)...); } }; int main() { i32 N; std::cin >> N; std::vector> graph(N); for (auto i: range(1, N)) { i32 u, v; std::cin >> u >> v; --u; --v; graph[u].push_back(v); graph[v].push_back(u); } std::vector> subtree(N); for (auto i: range(0, N)) { subtree[i].resize(graph[i].size()); } fix_point([&](auto dfs, i32 u, i32 p) -> i32 { i32 res = 1; for (auto i: range(0, graph[u].size())) { i32 v = graph[u][i]; if (v != p) { subtree[u][i] = dfs(v, u); res += subtree[u][i]; } } return res; })(0, -1); for (auto i: range(0, N)) { i64 ans = 0; i32 sum = 0; for (auto x: subtree[i]) { sum += x; ans -= (i64) x * x; } ans += (i64) sum * sum; std::cout << ans + sum * 2 + 1 << '\n'; } return 0; }