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

const int maxn=200005;
int n,ql,qr,lst,s,t;
vector<int>edge[maxn];
int dist[maxn],par[maxn],dep[maxn],que[maxn],ans[maxn];
bool bad[maxn];

void bfs(int s){
	for(int i=1;i<=n;i++)dist[i]=-1;
	dist[s]=0;
	ql=1;qr=0;
	que[++qr]=s;
	while(ql<=qr){
		int x=que[ql++];
		for(int i=0;i<int(edge[x].size());i++){
			int y=edge[x][i];
			if(dist[y]<0)dist[y]=dist[x]+1,par[y]=x,que[++qr]=y;
		}
	}
}

void dfs(int x,int p){
	lst=x;
	int yy=0;
	for(int i=0;i<int(edge[x].size());i++){
		int y=edge[x][i];
		if(y==p)continue;
		if(!bad[y])
			ans[y]=ans[lst]+dist[lst]+dist[y]-2*dist[x],dfs(y,x);
		else yy=y;
	}
	if(yy)
		ans[yy]=ans[lst]+dist[lst]+dist[yy]-2*dist[x],dfs(yy,x);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	bfs(1);
	for(int i=1;i<=n;i++)if(!s||dist[i]>dist[s])s=i;
	bfs(s);
	for(int i=1;i<=n;i++)if(!t||dist[i]>dist[t])t=i;
	while(t!=s)bad[t]=true,t=par[t];
	ans[s]=1;
	dfs(s,0);
	for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n?'\n':' ');
	return 0;
}
#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n;
int dep[maxn], ans[maxn], mx[maxn];
vector<int> g[maxn];

inline void findFar(int u, int p, int &s){
	if(~p)
		dep[u] = dep[p] + 1;
	else
		dep[u] = 0;
	if(!~s || dep[u] > dep[s])
		s = u;
	mx[u] = 1;
	FOR(i, 0, g[u].size()) if(g[u][i] != p)
		findFar(g[u][i], u, s), mx[u] = max(mx[u], mx[g[u][i]] + 1);
	return;
}

inline void dfs(int u, int p, int &clk){
	ans[u] = clk;
	vector<pii> son;
	FOR(i, 0, g[u].size()){
		int v = g[u][i];
		if(v == p)
			continue;
		son.PB(MP(mx[v], v));
	}
	sort(son.begin(), son.end());
	FOR(i, 0, son.size())
		dfs(son[i].snd, u, ++clk);
	++clk;
	return;
}

int main(){
	scanf("%d", &n);
	FOR(i, 1, n){
		int u, v; scanf("%d%d", &u, &v);
		--u; --v;
		g[u].PB(v); g[v].PB(u);
	}
	
	int s = -1, t = -1;
	findFar(0, -1, s);
	findFar(s, -1, t);
	
	int clk = 1;
	dfs(s, -1, clk);
	
	FOR(i, 0, n)
		printf("%d ", ans[i]); puts("");
	return 0;
}
