#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 4e5 + 5;
ll n;
vector<ll> v[maxn];
ll idx = 0, mx = 0;
ll dep[maxn];
ll L, R;
ll dfn[maxn], sz[maxn], dfsc;
void dfs(ll now, ll fa){
	dfn[now] = ++dfsc;
	sz[now] = 1;
	for(int i = 0;i < v[now].size();i++){
		ll t = v[now][i];
		if(t == fa) continue;
		dep[t] = dep[now] + 1;
		dfs(t, now);
		sz[now] += sz[t];
	}
	if(dep[now] >= mx) idx = now;
	mx = max(mx, dep[now]);
	return ;
}
ll p[maxn], len, e[maxn];
ll anc[maxn][21];
void dfs1(ll now, ll fa, ll x){
	p[++len] = now;
	anc[now][0] = fa;
	for(int i = 1;(1 << i) <= dep[now];i++){
		anc[now][i] = anc[anc[now][i - 1]][i - 1];
	}
	for(int i = 0;i < v[now].size();i++){
		ll t = v[now][i];
		if(t == fa) continue;
		dep[t] = dep[now] + 1;
		if(dfn[x] >= dfn[t] && dfn[x] <= dfn[t] + sz[t] - 1) continue;
		dfs1(t, now, x);
	}
	for(int i = 0;i < v[now].size();i++){
		ll t = v[now][i];
		if(t == fa) continue;
		if(dfn[x] >= dfn[t] && dfn[x] <= dfn[t] + sz[t] - 1){
			dfs1(t, now, x);
		}
	}
	return ;
}
ll lca(ll u, ll v){
	if(dep[u] < dep[v]) swap(u, v);
	ll cnt = dep[u] - dep[v];
	for(int i = 20;i >= 0;i--){
		if((cnt >> i) & 1) u = anc[u][i];
	}
	if(u == v) return u;
	for(int i = 20;i >= 0;i--){
		if(anc[u][i] != anc[v][i]){
			u = anc[u][i], v = anc[v][i];
		}
	}
	return anc[u][0];
}
int main(){
	scanf("%lld", &n);
	for(int i = 1;i < n;i++){
		ll ux, vx;
		scanf("%lld %lld", &ux, &vx);
		v[ux].push_back(vx);
		v[vx].push_back(ux);
	}
	dfs(1, 0); L = idx;
	dfsc = 0;
	dfs(L, 0); R = idx;
	dfs1(L, 0, R);
	ll sum = 1;
	for(int i = 1;i <= n;i++){
		e[p[i]] = sum;
		sum += dep[p[i]] + dep[p[i + 1]] - 2 * dep[lca(p[i], p[i + 1])];
	}
	for(int i = 1;i <= n;i++){
//		cout << p[i] << " " << p[i + 1] << " ";
		printf("%lld ", e[i]);
//		puts("");
	}
	puts("");
	return 0;
}
#include <cstdio>
const int maxn=2e5+10;
struct E{
	int to;
	int next;
}ed[maxn*2];
int head[maxn];
int tot;
void J(int a,int b){
	ed[++tot].to=b;
	ed[tot].next=head[a];
	head[a]=tot;
}
int dep[maxn];
int s;
int t;
void Dfs1(int x,int fa){
	dep[x]=dep[fa]+1;
	if(!s||dep[x]>dep[s])
		s=x;
	for(int i=head[x];i;i=ed[i].next){
		if(ed[i].to==fa)
			continue;
		Dfs1(ed[i].to,x);
	}
}
int f[maxn];
void Dfs2(int x,int fa){
	dep[x]=dep[fa]+1;
	f[x]=fa;
	if(!t||dep[x]>dep[t])
		t=x;
	for(int i=head[x];i;i=ed[i].next){
		if(ed[i].to==fa)
			continue;
		Dfs2(ed[i].to,x);
	}
}
int now;
int bj[maxn];
int top;
int sta[maxn];
int e[maxn];
void Dfs3(int x,int fa){
	e[x]=now;
	for(int i=head[x];i;i=ed[i].next){
		if(ed[i].to==fa)
			continue;
		now++;
		Dfs3(ed[i].to,x);
		now++;
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		J(u,v);
		J(v,u);
	}
	Dfs1(1,0);
	Dfs2(s,0);
	int tmp=t;
	while(tmp){
		sta[++top]=tmp;
		bj[tmp]=1;
		tmp=f[tmp];
	}
	for(int i=1;i<=top;i++){
		e[sta[i]]=++now;
		for(int j=head[sta[i]];j;j=ed[j].next){
			if(!bj[ed[j].to]){
				now++;
				Dfs3(ed[j].to,sta[i]);
				now++;
			}
		}
	}
	for(int i=1;i<=n;i++)
		printf("%d ",e[i]);
	return 0;
}