#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector> G(N); rep(i,N-1) { int a,b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } int ROOT = 0, SUM = 0; vector ans(N, 0); function dfs = [&](int v, int p) -> void { for(int to : G[v]) { if(to != p) { ans[to] = ans[v] + (v < to ? 1 : -1); SUM += (v > to); dfs(to, v); } } }; dfs(ROOT, -1); rep(i,N) cout << SUM + ans[i] << "\n"; }