#include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define INF 1<<30 #define MP make_pair #define mp make_pair #define pb push_back #define PB push_back #define DEBUG(x) cout<<#x<<": "< to[100010]; int a[100010]; int depth[100010]; int len[100010]; int dfs(int tar,int dep,int par){ depth[tar]=dep; int ans=INF; REP(i,to[tar].size()){ ans=min(ans,dfs( to[tar][i], dep+1,tar)); } if(ans==INF) return len[tar]=0; len[tar]= min(len[par],1+ans); return len[tar]; } void dfs2(int tar,int par){ REP(i,to[tar].size()){ dfs2(to[tar][i],tar); } len[tar] = min(len[par]+1,len[tar]); } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>n; REP(i,n-1){ int a,b;cin>>a>>b; to[a].pb(b); } fill(len,len+n+1,INF); dfs(1,0,1); dfs2(1,1); FOR(i,1,n+1) cout<