#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set> 
#include<iomanip>
#define IOS 	cin.tie(0), ios::sync_with_stdio(false) 
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 2e5 + 10, M = N * 2, mod = 1e9 + 7;
const double eps = 1e-4;
const double pi = acos(-1);
const int P = 131;

int h[N], e[M], ne[M], idx;
int res[N], f[N], son[N];
int n, maxd, d, cnt;

void add(int a, int b)
{
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx ++;
}

void dfs1(int u, int fa, int dis)
{
	f[u] = fa;
	if(dis >= maxd)
	{
		d = u;
		maxd = dis;
	}
	
	for(int i = h[u] ; ~i ; i = ne[i])
	{
		int j = e[i];
		if(j == fa) continue;
		dfs1(j, u, dis + 1);
	}
}

void dfs(int u, int fa)
{
	res[u] = ++ cnt;
	for(int i = h[u] ; ~i ; i = ne[i])
	{
		int j = e[i];
		if(j == fa || j == son[u]) continue;
		dfs(j, u);
	}
	if(son[u])
		dfs(son[u], u);
	cnt ++;
}

int main()
{
	IOS; 
	cin >> n;
	memset(h, -1, sizeof h);
	for(int i = 1 ; i < n ; i ++)
	{
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	dfs1(1, 0, 0);	//找到能从1遍历到的最远的点 d 
	int s = d; 		//记录下直径的一个端点 
	dfs1(s, 0, 0);	//找到树的直径 
	for(int i = d ; i ; i = f[i])	//标记直径上所有的点 
		son[f[i]] = i;
	dfs(s, 0);
	
	for(int i = 1 ; i <= n ; i ++)
		cout << res[i] << " ";
	
	return 0;
}
// Arti1990, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007LL

using namespace std;

int n, a, b, id;

struct wierzch
{
    int d;
    int id;
    int syn;
    vector <int> l;
};
wierzch tab[1000007];

int najdalszy(int nr, int o)
{
//    cout << "najdalszy w " << nr << endl;
    int best = nr;
    tab[nr].syn = nr;

    for(auto el : tab[nr].l)
    {
        if(el != o)
        {
            tab[el].d = tab[nr].d+1;
            int r = najdalszy(el, nr);
            if(tab[r].d > tab[best].d)
            {
                best = r;
                tab[nr].syn = el;
            }
        }
    }
//    cout << "best: " << best << endl;
    return best;
}

void dfs(int nr, int o)
{
    id++;
    tab[nr].id = id;

    for(auto el : tab[nr].l)
    {
        if(el != o && el != tab[nr].syn)
        {
            dfs(el, nr);
        }
    }
    if(tab[nr].syn != nr)
        dfs(tab[nr].syn, nr);
    id++;
}

int solve()
{
    scanf("%d", &n);
    forr(i, n-1)
    {
        scanf("%d %d", &a, &b);
        tab[a].l.PB(b);
        tab[b].l.PB(a);
    }

    int u = najdalszy(1, 1);
    int v = najdalszy(u, u);

    id = 0;
    dfs(u, u);

    FOR(i, 1, n)
        printf("%d ", tab[i].id);
    printf("\n");

    return 0;
}

int main()
{
    solve();

    return 0;
}
