#include #include #include #include using namespace std; typedef vector VI; typedef vector VVI; typedef pair PII; #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) int main(){ int N,x,y,d=0,h; PII tmp; VVI e; VI S; queue n; cin >> N; e = VVI(N); S = VI(N,N); rep(i,N-1){ cin >> x >> y; x--; y--; e[x].push_back(y); e[y].push_back(x); } n.push(PII(0,0)); rep(i,N) if(e[i].size() == 1) n.push(PII(0,i)); while(!n.empty()){ tmp = n.front(); d = tmp.first; h = tmp.second; n.pop(); if(d >= S[h]) continue; S[h] = d; each(nxt, e[h]) n.push(PII(d+1,*nxt)); } rep(i,N) cout << S[i] << endl; return 0; }