#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=5e5+5,mod=3;
int n,rt,dep[N],son[N];
vector<int>e[N];
void dfs(int u,int p)
{
    dep[u]=dep[p]+1;
    if(dep[u]>dep[rt]) rt=u;
    for(int v:e[u])
        if(v!=p)
        dfs(v,u);
}
void dfs2(int u,int p)
{
    dep[u]=1;
    for(int v:e[u])
        if(v!=p)
        {
            dfs2(v,u);
            if(dep[v]+1>dep[u])
                dep[u]=dep[v]+1,son[u]=v;
        }
}
int id,ans[N];
void dfs3(int u,int p)
{
    ans[u]=++id;
    for(int v:e[u])
        if(v!=son[u]&&v!=p)
        dfs3(v,u);
    if(son[u]) dfs3(son[u],u);
    ++id;
}
int main()
{
    //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
    sc(n);
    rep(i,1,n-1)
    {
        int u,v;sc(u,v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1,0);
    dfs2(rt,0);
    dfs3(rt,0);
    rep(i,1,n)
    printf(i==n?"%d\n":"%d ",ans[i]);
}

#include<bits/stdc++.h>
// #pragma optimize("-O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,avx,mmx,tune=native")
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
//#define BIG_INF 1e18
#define vi vector<ll>
#define sz(a) ll((a).size())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1)
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// typedef tree<
// ll,
// null_type,
// less<ll>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;
typedef long long ll;
const ll BIG_INF = 4e18;
const ll mod = 1e9 + 7;
 ll fast_exp(ll a, ll b)
{
    if(b <= 0)
       return 1;
    else
    {
       ll res = 1;
       res = fast_exp(a,b/2);
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;
 
    }
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
long long true_rand(long long n) {
    // Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_int_distribution<long long> uid(0, n - 1);
    return uid(rng);
}
typedef double ld;
const long long N = 2e5+1000;
const long double pi = acos(-1.0);
using cd = complex<double>;
const double PI = acos(-1);
ld eps = 1e-12;
int vis[N] = {};
vector <int> edge[N];
int farthest = 1, dist = 0;
int dia_2;
void dfs(int v, int cur_dist)
{
    vis[v] = 1;
    if(cur_dist > dist)
    {
        farthest = v;
        dist = cur_dist; 
    }
    for(auto e: edge[v])
    {
        if(vis[e] == 0)
        {
            dfs(e,cur_dist+1);
        }
    }
}
int col[N] = {};
void color(int v)
{
    vis[v] = 1;
    if(v == dia_2)
        col[v] =1;
    for(auto e: edge[v])
    {
        if(vis[e] == 0)
        {
            color(e);
            col[v] = max(col[v],col[e]);
        }
    }
}

int global_num = 1;
int final_num[N] = {};
void final_dfs(int v)
{
    vis[v] = 1;
    final_num[v] = global_num;
    for(auto e: edge[v])
    {
        if(vis[e] == 0 && col[e] == 0)
        {
            global_num++;
            final_dfs(e);
            global_num++;
        }
    }
    for(auto e: edge[v])
    {
        if(vis[e] == 0 && col[e] == 1)
        {
            global_num++;
            final_dfs(e);
            global_num++;
        }
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("c.txt","r",stdin);
    // freopen("input.txt", "w", stdout);
    int n;
    cin >> n;
    int u, v;
    for(int i = 0; i < n-1; i++)
    {
        cin >> u >> v;
        edge[u].pb(v);
        edge[v].pb(u);
    }
    dfs(1,0);
    int dia_1 = farthest;
    int dia_1_dist = dist;
    farthest = dia_1;
    dist = 0;
    for(int i = 1; i<=n; i++)
        vis[i] = 0;
    dfs(dia_1,0);
    dia_2 = farthest;

    for(int i = 1; i<=n; i++)
        vis[i] = 0;
    color(dia_1);
    for(int i = 1; i<=n; i++)
        vis[i] = 0;

    final_dfs(dia_1);
    for(int i = 1; i <= n; i++)
        cout << final_num[i] << " ";
    cout << '\n';



    // cout << "Case #" << cs++ << ": " << ans << '\n';
   
    return 0;
       
        
    
    
}










     