#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using std::vector; constexpr int MAX_N = 100000; struct Solver { Solver(int n, vector>& g) : N(n), graph(g), memo(n) {} int N; vector> graph; vector memo; int dfs(int num, int difference = 0, int parent = -1) { int result = 0; // memo[num] = difference; for (int next : graph[num]) { if (next == parent) continue; if (num > next) ++result; result += dfs(next, difference + (num > next ? -1 : 1), num); } return result; } vector solve() { vector result(N); for (int i = 0; i < N; ++i) { result[i] = dfs(i); } return std::move(result); } }; int main() { int N; std::scanf("%d", &N); vector graph(N, vector()); for (int i = 0; i < N - 1; ++i) { int A, B; std::scanf("%d%d", &A, &B); --A; --B; graph[A].push_back(B); graph[B].push_back(A); } Solver solver(N, graph); for (int answer : solver.solve()) { std::printf("%d\n", answer); } }