#include using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; void solve() { int N; std::cin >> N; std::vector> g(N); for(int i = 0; i < N - 1; i ++) { int A, B; std::cin >> A >> B; A --; B --; g[A].push_back(B); g[B].push_back(A); } std::vector diff(N); auto dfs = [&](auto& self, int now = 0, int per = -1) -> int{ int Z = 0; for(auto to : g[now]) { if(to == per) continue; diff[to] = diff[now] + (to > now ? 1 : -1); Z += self(self, to, now) + (to < now); } return Z; }; int ans = dfs(dfs); for(int i = 0; i < N; i ++) std::cout << ans + diff[i] << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; //std::cin >> T; while (T--) { solve(); } return 0; }