#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int main(){ int N; while(cin >> N){ vector G(N + 1); rep(i, N - 1){ int x, y; scanf("%d%d", &x, &y); --x; --y; G[x].push_back(y); G[y].push_back(x); } vi ans(N); queue Q; rep(i, N)if(sz(G[i]) == 1 || i == 0){ Q.push(mp(0, i)); } vi vis(N); while(sz(Q)){ int d, v; tie(d, v) = Q.front(); Q.pop(); if(vis[v]++)continue; ans[v] = d; each(w, G[v]){ Q.push(mp(d + 1, w)); } } rep(i, N)printf("%d\n", ans[i]); } }