#include #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using graph=vector>; void add_undirected_edge(graph& G,int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } const int INF=1<<29; graph T; int dep[100000],res[100000]; void dfs(int u,int p){ res[u]=(p!=-1&&T[u].size()==1?0:INF); for(int v:T[u]) if(v!=p) { dep[v]=dep[u]+1; dfs(v,u); res[u]=min(res[u],res[v]+1); } } int main(){ int n; scanf("%d",&n); T.resize(n); rep(i,n-1){ int u,v; scanf("%d%d",&u,&v); u--; v--; add_undirected_edge(T,u,v); } dfs(0,-1); rep(u,n) printf("%d\n",min(dep[u],res[u])); return 0; }