#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; vector> G; void make_graph(int N) { G.resize(N); int x, y; rep(i, N-1) { cin >> x >> y; x--, y--; G[x].push_back(y); G[y].push_back(x); } } vi rev; int rec1(int x, int from) { int a = 0; for (auto t : G[x]) { if (t == from) continue; a += rec1(t, x); if (x > t) a++; } return a; } void rec2(int x, int from) { for (auto t : G[x]) { if (t == from) continue; if (x > t) rev[t] = rev[x]-1; else rev[t] = rev[x]+1; rec2(t, x); } } int main() { lint N; cin >> N; make_graph(N); rev.resize(N); lint a=0, b=0, c=0, x, y, z; rev[0] = rec1(0, 0); rec2(0, 0); rep(i, N) std::cout << rev[i] << '\n'; }