#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N;
int to[400001], ne[400001], he[200001];
int Q[200001], vis[200001], p, q;
ll are[200001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	cin >> N;
	rep1(i, N * 2 - 2) {
		int a, b;
		cin >> a >> b;
		to[i] = b;
		ne[i] = he[a];
		he[a] = i++;
		to[i] = a;
		ne[i] = he[b];
		he[b] = i;
	}

	Q[q++] = 1;
	while (p < q) {
		int u = Q[p++];
		vis[u] = -1;
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] == 0) {
				Q[q++] = to[i];
			}
		}
	}
	int tmp = Q[N - 1];
	p = 0;
	q = 0;
	Q[q++] = tmp;
	vis[tmp] = 0;
	while (p < q) {
		int u = Q[p++];
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] < 0) {
				vis[to[i]] = u;
				Q[q++] = to[i];
			}
		}
	}
	ll m = (1ll << 20) - 1, m0 = ~m, m1 = 1ll << 20;
	for (int i = N - 1; i >= 0; i--) {
		int u = Q[i];
		ll kari = (are[u] & m0) + m1 + u;
		if (are[vis[u]] < kari) are[vis[u]] = kari;
	}

	int k = 0;
	q = 0;
	Q[q++] = tmp;
	while (q) {
		k++;
		int u = Q[q - 1];
		if (u < 0) q--;
		else {
			vis[u] = -k;
			Q[q - 1] = -u;
			int nanika = are[u] & m;
			if(nanika) Q[q++] = nanika;
			for (int i = he[u]; i; i = ne[i]) {
				int v = to[i];
				if (vis[v] >= 0 && v != nanika) {
					Q[q++] = v;
				}
			}
		}
	}

	rep1(i, N) cosp(-vis[i]);

	Would you please return 0;
}
#include <iostream>
#include <cstdio>
const int nn = 2e5 + 5;
int n, ans[nn], tot;
int cnt, prev[nn << 1], last[nn], to[nn << 1];
void addedge(int p, int q) {
	prev[++cnt] = last[p];
	to[last[p] = cnt] = q;
}
int dep[nn], son[nn];
void dfs1(int p, int fa) {
	for (int i = last[p]; i; i = prev[i]) {
		if (to[i] != fa) {
			dfs1(to[i], p);
			if (dep[p] < dep[to[i]] + 1) {
				dep[p] = dep[to[i]] + 1;
				son[p] = to[i];
			}
		}
	}
}
void dfs2(int p, int fa) {
	ans[p] = ++tot;
	for (int i = last[p]; i; i = prev[i])
		if (to[i] != fa && to[i] != son[p])
			dfs2(to[i], p);
	if (son[p]) dfs2(son[p], p);
	++tot;
}
int main() {
	scanf("%d", &n);
	for (int i = 1, p, q; i < n; i++) {
		scanf("%d %d", &p, &q);
		addedge(p, q);
		addedge(q, p);
	}
	dfs1(1, 0);
	int p = 1;
	while (son[p]) p = son[p];
	for (int i = 1; i <= n; i++)
		dep[i] = son[i] = 0;
	dfs1(p, 0); dfs2(p, 0);
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
}