#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
//typedef pair<int,int> P;
#define rep(i,l,r) for (int i(l);i<=int(r);i++)
#define per(i,l,r) for (int i(r);i>=int(l);i--)
#define all(x) (x).begin(),(x).end()
#define forall(x,y) for (const int &y: e[x])

int n;
vector<int> e[200010];
int w[200010],q;

int fat[200010],dep[200010];
void dfs0(int x,int f,int d){
	fat[x]=f; dep[x]=d;
	forall(x,y) if (y^f) dfs0(y,x,d+1);
}
void dfs1(int x,int f){
	w[x]=++q;
	forall(x,y) if (y^f) dfs1(y,x),++q;
}

void solve(){
	n=read();
	rep(i,2,n){
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}
	dfs0(1,0,1);
	const int S=max_element(dep+1,dep+n+1)-dep;
	dfs0(S,0,1);
	const int T=max_element(dep+1,dep+n+1)-dep;
	static int p[200010],m;
	for (int i=T;i;i=fat[i]) p[++m]=i;
	reverse(p+1,p+m+1);
	rep(i,1,m){
		const int &x=p[i];
		w[x]=++q;
		forall(x,y) if (y!=p[i+1]&&y!=p[i-1]) dfs1(y,x),++q;
	}
	rep(i,1,n) printf("%d ",w[i]);
	puts("");
}

int main()
{
	for (int T=1;T--;) solve();
	return 0;
}
/*
    /\ In The Name Of Allah /\
    Author : Jawahiir Nabhan
*/
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const char nl = '\n';
const int NM = 2e5 + 10;

int dis[NM],order[NM],vis[NM],depth[NM];
int N,cnt = 1;
vector <int> g[NM];
void dfs1(int u)
{
    vis[u] = 1;
    for(int v : g[u]){
        if(vis[v]) continue;
        dfs1(v);
        depth[u] = max(depth[u], depth[v] + 1);
    }
}
void dfs2(int u)
{
    order[u] = cnt;
    vis[u] = 1;
    vector <pair<int, int>> vec;
    for(int v : g[u])
    {
        if(vis[v]) continue;
        vec.pb({depth[v], v});
    }
    sort(vec.begin(),vec.end());
    for(auto &[x, y] : vec)
    {
        cnt++;
        dfs2(y);
        cnt++;
    }
}
int main()
{
    cin>> N;
    for(int i = 1;i <= N - 1;i++){
        int u,v; cin>> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i = 1;i <= N;i++) dis[i] = (1 << 30);
    queue <int> q;
    q.push(1);
    dis[1] = 0;
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int v : g[u]){
            if(dis[v] == (1 << 30))
            {
                q.push(v);
                dis[v] = dis[u] + 1;
            }
        }
    }
    int pos,mx = -1;
    for(int i = 1;i <= N;i++){
        if(dis[i] > mx){
            mx = dis[i];
            pos = i;
        }
    }
    dfs1(pos);
    for(int i = 1;i <= N;i++) vis[i] = 0;
    dfs2(pos);
    for(int i = 1;i <= N;i++) cout<< order[i] << ' ';
    cout<< nl;
}
