#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define mxn 300007
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using namespace std;
vector<ll>g[mxn];
ll dis1[mxn],dis2[mxn],dis3[mxn],vis3[mxn],en,mx=-inf,en2,ans[mxn];
bool vis1[mxn],vis2[mxn];
int main(void){
#ifndef ONLINE_JUDGE
freopen("input1.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
fast;
int n,i,a,b;
cin>>n;
for(i=1;i<=n-1;i++){
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
queue<int>q;
q.push(1);
while(!q.empty()){
int k=q.front();
q.pop();
vis1[k]=1;
for(auto x:g[k]){
if(vis1[x])
continue;
q.push(x);
dis1[x]=dis1[k]+1;
vis1[x]=1;
if(dis1[x]>mx){
mx=dis1[x];
en=x;
}
}
}
q.push(en);
mx=0;
while(!q.empty()){
int k=q.front();
q.pop();
vis2[k]=1;
for(auto x:g[k]){
if(vis2[x])
continue;
q.push(x);
dis2[x]=dis2[k]+1;
vis2[x]=1;
if(dis2[x]>mx){
mx=dis2[x];
en2=x;
}
}
}
//cout<<en<<' '<<en2<<endl;
for(i=1;i<=n;i++){
if(dis2[i]==mx)
ans[i]=mx+1;
else
ans[i]=max(ans[i],mx);
}
q.push(en2);
while(!q.empty()){
int k=q.front();
q.pop();
vis3[k]=1;
for(auto x:g[k]){
if(vis3[x])
continue;
q.push(x);
dis3[x]=dis3[k]+1;
vis3[x]=1;
if(dis3[x]>mx){
mx=dis3[x];
}
}
}
for(i=1;i<=n;i++){
if(dis3[i]==mx)
ans[i]=mx+1;
else
ans[i]=max(ans[i],mx);
}
for(i=1;i<=n;i++)
cout<<ans[i]<<' ';
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8aW9tYW5pcD4KI2RlZmluZSBmYXN0IHtpb3NfYmFzZTo6c3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