#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int,int> Pii;
#define reg register
#define mp make_pair
#define pb push_back
#define Mod1(x) ((x>=P)&&(x-=P))
#define Mod2(x) ((x<0)&&(x+=P))
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); }
template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); }

char IO;
template <class T=int> T rd(){
	T s=0; int f=0;
	while(!isdigit(IO=getchar())) f|=IO=='-';
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=2e5+10,INF=1e9+10;

int n;
vector <int> G[N];
int F[N][20],D[N],E[N],L[N];
int ma=-1,id;
void dfs(int u,int f) {
	if(D[u]>ma) ma=D[u],id=u;
	F[u][0]=f,E[u]=D[u];
	rep(i,1,18) F[u][i]=F[F[u][i-1]][i-1];
	for(int v:G[u]) if(v!=f) D[v]=D[u]+1,dfs(v,u),cmax(E[u],E[v]);
	L[u]=G[u][0]==f?(G[u].size()==1?0:G[u][1]):G[u][0];
	sort(G[u].begin(),G[u].end(),[&](int x,int y){ return E[x]<E[y]; });
}
int LCA(int x,int y){
	if(D[x]<D[y]) swap(x,y);
	for(int del=D[x]-D[y],i=0;(1<<i)<=del;++i) if(del&(1<<i)) x=F[x][i];
	if(x==y) return x;
	drep(i,18,0) if(F[x][i]!=F[y][i]) x=F[x][i],y=F[y][i];
	return F[x][0];
}
int Dis(int x,int y){ return D[x]+D[y]-2*D[LCA(x,y)]; }

int lst;
ll Ans=1e18,A[N],M,B[N];
void dfs2(int u,int f) {
	//cout<<u<<' ';
	if(!lst) A[lst=u]=1;
	else A[u]=A[lst]+Dis(lst,u),lst=u;
	M=A[u];
	for(int v:G[u]) if(v!=f) dfs2(v,u);
}

void Work(int u){
	lst=0;
	dfs(u,0),dfs2(u,0);
	if(M<Ans) {
		Ans=M;
		rep(i,1,n) B[i]=A[i];
	}
	//puts("");
}

int main(){
	n=rd();
	rep(i,2,n) {
		int u=rd(),v=rd();
		G[u].pb(v),G[v].pb(u);
	}
	dfs(1,0),Work(id);
	int u=1;
	while(L[u]) u=L[u];
	Work(u);
	while(L[u]) u=L[u];
	Work(u);
	ll ans=0;
	rep(i,1,n) cmax(ans,B[i]);
	//printf("%lld\n",ans);
	rep(i,1,n) printf("%lld ",B[i]);
}






#include<bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long

const int nax = 2e5+5;
vector<int> edges[nax];
vector<int> value , d , par;
int cp = 1;

void dfs(int u , int p = -1 , int _d = 0){
	par[u] = p;
	d[u] = _d;
	for(auto x : edges[u]){
		if(x != p){
			dfs(x,u,_d+1);
		}
	}
}

void dfs1(int u , int p){
	value[u] = cp++;
	for(auto x : edges[u]){
		if(x != p){
			dfs1(x,u);
		}
	}
	cp++;
}

void test(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n-1 ; i++){
		int x, y;
		cin >> x >> y;
		x-- , y-- ;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	value.resize(n);
	d.resize(n);
	par.resize(n);
	dfs(0);
	int st = max_element(d.begin(),d.end())-d.begin();
	dfs(st);
	int en = max_element(d.begin(),d.end())-d.begin();
	value[en] = cp++;
	while(par[en] != -1){
		int p = par[en];
		value[p] = cp++;
		for(auto x : edges[p]){
			if(x != par[p] && x != en){
				dfs1(x,p);
			}
		}
		en = p;
	}
	for(auto x : value)
		cout<<x<<" ";
}

int32_t main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	// cin >> T;
	while(T--){
		test();
	}
}

// 0 0 3