#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
vector<vector<int>> E;
ll vis[202020];
int have[202020];

ll id=1;
pair<int,int> farthest(vector<vector<int>>& E, int cur,int pre,int d,vector<int>& D) {
	D[cur]=d;
	pair<int,int> r={d,cur};
	FORR(e,E[cur]) if(e!=pre) r=max(r, farthest(E,e,cur,d+1,D));
	return r;
}

pair<int,vector<int>> diameter(vector<vector<int>>& E) { // diameter,center
	vector<int> D[2];
	D[0].resize(E.size());
	D[1].resize(E.size());
	auto v1=farthest(E,0,0,0,D[0]);
	auto v2=farthest(E,v1.second,v1.second,0,D[0]);
	farthest(E,v2.second,v2.second,0,D[1]);
	pair<int,vector<int>> R;
	R.first = v2.first;
	//両端を取る場合
	R.second.push_back(v1.second);
	R.second.push_back(v2.second);

	return R;
}

int dfs1(int cur,int pre,int tar) {
	if(cur==tar) have[cur]=1;
	vis[cur]=id;
	FORR(e,E[cur]) if(e!=pre) {
		have[cur]|=dfs1(e,cur,tar);
	}
	return have[cur];
}
void dfs2(int cur,int pre) {
	
	vis[cur]=id;
	FORR(e,E[cur]) if(e!=pre) {
		if(have[e]==0) {
			id++;
			dfs2(e,cur);
		}
	}
	FORR(e,E[cur]) if(e!=pre) {
		if(have[e]) {
			id++;
			dfs2(e,cur);
		}
	}
	id++;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	E.resize(N);
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	
	auto a=diameter(E);
	
	x=a.second[0];
	y=a.second[1];
	dfs1(x,x,y);
	dfs2(x,x);
	FOR(i,N) cout<<vis[i]<<" ";
	cout<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <cstdio>
#include <vector>
const int maxn = 2e5+5;
int n,ans[maxn],maxx,X,Y;
int head[maxn],tot;
struct Edge{
	int next,to;
}e[maxn<<1];
void add_edge(int x,int y){
	e[++tot].next = head[x];
	e[tot].to = y,head[x] = tot;
}
int fa[maxn],top[maxn],siz[maxn],dep[maxn],son[maxn],Flag[maxn];
void dfs1(int u,int F){
	siz[u] = 1,fa[u] = F,dep[u] = dep[F] + 1;
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next){
		if(v == F)continue;
		dfs1(v,u);
		siz[u] += siz[v];
		if(siz[v] > siz[son[u]])son[u] = v;
	}
}
void dfs2(int u,int T){
	top[u] = T;
	if(son[u])dfs2(son[u],T);
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
		if(v != son[u] && v != fa[u])
			dfs2(v,v);
}
int LCA(int x,int y){
	while(top[x]^top[y]){
		if(dep[top[x]]<dep[top[y]])x^=y^=x^=y;
		x = fa[top[x]];
	}return dep[x]<dep[y]?x:y;
}
void getchain(int u,int F){
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next){
		if(v == F)continue;
		getchain(v,u);
		if(Flag[v])Flag[u] = 1;
	}
}
int Dis(int x,int y){return dep[x]+dep[y]-2*dep[LCA(x,y)];}
int nowans,pre;
void getans(int u,int F){
	ans[u] = (nowans+=Dis(u,pre)),pre = u;
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
		if(Flag[v] == 0 && v != F)
			getans(v,u);
	for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
		if(v != F && Flag[v] == 1)
			getans(v,u);
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<n;++i)
		scanf("%d %d",&x,&y),add_edge(x,y),add_edge(y,x);
	dfs1(1,0),maxx = 0;
	for(int i=1;i<=n;++i)if(maxx < dep[i])maxx = dep[i],X = i;
	for(int i=1;i<=n;++i)fa[i] = son[i] = dep[i] = siz[i] = 0;
	dfs1(X,0),maxx = 0,dfs2(X,X);
	for(int i=1;i<=n;++i)if(maxx < dep[i])maxx = dep[i],Y = i;
	Flag[Y] = 1,getchain(X,0);
	nowans = 1,pre = X,getans(X,0);
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
	return 0;
}