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

#define Mod(x) (x>=P)&&(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)
#define erep(i,a) for(int i=hd[a];i;i=nxt[i])

typedef long long ll;
void Max(int &x,int y){(x<y)&&(x=y);}
void Min(int &x,int y){(x>y)&&(x=y);}

bool vio;
char IO;
int rd(int res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const int M=1e6+10;
int nxt[M<<1],to[M<<1],hd[M],ecnt;
void Add(int a,int b){
	nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b;
}
int Mx,tp,bot,L[M],R[M],n;
void dfs(int x,int f,int d){
	static int tot;
	if(d>Mx)tp=x,Mx=d;
	L[x]=++tot;
	erep(i,x){
		int y=to[i];
		if(y==f)continue;
		dfs(y,x,d+1);
	}
	R[x]=tot;
}
bool FA(int a,int b){
	return L[a]<=L[b]&&L[b]<=R[a];
}
int nw=1,ans[M];
void redfs(int x,int f){
	ans[x]=nw;
	erep(i,x){
		int y=to[i];
		if(y==f||FA(y,tp))continue;
		nw++,redfs(y,x);
	}
	erep(i,x){
		int y=to[i];
		if(y!=f&&FA(y,tp))nw++,redfs(y,x);
	}
	nw++;
}
bool let;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	rep(i,2,n=rd()){
		int a=rd(),b=rd();
		Add(a,b),Add(b,a);
	}
	Mx=0,dfs(1,0,0);
	bot=tp,Mx=0,dfs(tp,0,0);	
	ans[1]=1;
	redfs(bot,0);
	rep(i,1,n)printf("%d ",ans[i]);
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)						(x).begin(),(x).end()
#define X							first
#define Y							second
#define sep							' '
#define endl						'\n'
#define SZ(x)						ll(x.size())

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;

int n , timer , R[MAXN] , H[MAXN] , st[MAXN] , fn[MAXN];
vector<int> adj[MAXN];

int cmp(int i , int j){
	return R[i] < R[j];
}

void DFS(int v , int p = -1){
	st[v] = ++timer;
	R[v] = H[v] = (p == -1 ? 0 : H[p] + 1);
	sort(all(adj[v]) , cmp);
	for(int u : adj[v]){
		if(u == p)	continue;
		DFS(u , v);
		R[v] = max(R[v] , R[u]);
	}
	fn[v] = ++timer;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	cin >> n;
	for(int i = 1 ; i < n ; i++){
		int v , u;
		cin >> v >> u;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	DFS(1);
	int v = max_element(H , H + MAXN) - H;
	DFS(v);
	timer = 0; DFS(v);
	for(int i = 1 ; i <= n ; i++)	cout << st[i] << sep;

    return 0;
}
/*

*/