#include <bits/stdc++.h>
using i64 = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    std::vector<int> dis(n), parent(n);
    auto bfs = [&](int s) {
        std::fill(dis.begin(), dis.end(), -1);
        parent[s] = -1;
        dis[s] = 0;
        std::queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int u = que.front();
            que.pop();
            for (auto v : e[u]) {
                if (dis[v] == -1) {
                    dis[v] = dis[u] + 1;
                    parent[v] = u;
                    que.push(v);
                }
            }
        }
        return std::max_element(dis.begin(), dis.end()) - dis.begin();
    };
    int u = bfs(0);
    int v = bfs(u);
    std::vector<int> son(n, -1);
    for (int i = v; i != u; i = parent[i]) {
        son[parent[i]] = i;
    }
    std::vector<int> E(n, -1);
    int cur = 0;
    std::function<void(int)> dfs = [&](int u) {
        E[u] = ++cur;
        for (auto v : e[u]) {
            if (v != son[u] && E[v] == -1) {
                dfs(v);
                cur++;
            }
        }
        if (son[u] != -1) {
            dfs(son[u]);
            cur++;
        }
    };
    dfs(u);
    for (int i = 0; i < n; i++) {
        std::cout << E[i] << " \n"[i == n - 1];
    }
    return 0;
}
#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]);
}
