#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr ll LINF = 1e18; constexpr int MOD = 1000000007; int n = 100005; vector> tree(n,vector()); vector R(n,0); vector L(n,0); int dfs(int i,int p=-1,int d=0){ R[i] = d; int res = 0; for(int c:tree[i]){ if(c == p) continue; res = max(res,dfs(c,i,d+1)+1); } L[i] = res; return L[i]; } int main(){ cin >> n; rep(i,n-1){ int a,b; cin >> a >> b; --a;--b; tree[a].push_back(b); tree[b].push_back(a); } dfs(0); rep(i,n){ cout << min(L[i],R[i]) << endl; } return 0; }