/*
口台 口台
令人咍咍。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, dep[N], is[N], son[N], res[N], tim, p, q;
int e, to[N << 1], nxt[N << 1], hd[N];
void add(int u, int v){ to[++e] = v; nxt[e] = hd[u]; hd[u] = e; }
void dfs(int u, int fa){
	if(dep[u] > dep[p]) p = u;
	for(int i = hd[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa) continue;
		dep[v] = dep[u] + 1; dfs(v, u);
	}
	return;
}
void dfs2(int u, int fa){
	is[u] = (u == q); //printf("%d ", u); printf("%d\n", is[u]);
	for(int i = hd[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa) continue;
		dfs2(v, u); if(is[v]) is[u] = 1, son[u] = v; 
	}
	
	return;
}
void dfs3(int u, int fa){
	res[u] = ++tim;
	for(int i = hd[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa || v == son[u]) continue;
		dfs3(v, u);
	}
	if(son[u]) dfs3(son[u], u);
	++tim;
	return;
}
int main() {
	//freopen("ex.in", "r", stdin);
	//freopen("ex.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1, u, v; i < n; i++)
		scanf("%d%d", &u, &v), add(u, v), add(v, u);
	p = 1; dep[1] = 0; dfs(1, 0);
	q = p; dep[q] = 0; dfs(q, 0);
	//cout<<p<<" "<<q<<endl;
	dfs2(p, 0); dfs3(p, 0);
	//printf("%d\n", 2 * (n - 1) + 1 - dep[p]);
	for(int i = 1; i <= n; i++)
		printf("%d ", res[i]);
	return 0;
}
#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int N;
vector<int>to[200005];
int deep = -1;
int dmax = -1;
void dfs(int v, int d = 0, int p = -1) {
	if (d > dmax) {
		deep = v;
		dmax = d;
	}
	for (int e : to[v]) {
		if (p == e) { continue; }
		dfs(e, d + 1, v);
	}
}
int pre[200005];
int deep2 = -1;
int dmax2 = -1;
void dfs0(int v, int d = 0, int p = -1) {
	pre[v] = p;
	if (d > dmax2) {
		deep2 = v;
		dmax2 = d;
	}
	for (int e : to[v]) {
		if (p == e) { continue; }
		dfs0(e, d + 1, v);
	}
}
set<int>st;
int now = 0;
int a[200005];
void dfs2(int v, int d = 0, int p = -1) {
	now++;
	if (0 == a[v]) {
		a[v] = now;
	}
	int last = -1;
	for (int e : to[v]) {
		if (p == e) { continue; }
		if (st.count(e)) {
			last = e;
			continue;
		}
		dfs2(e, d + 1, v);
		now++;
	}
	if (-1 != last) {
		dfs2(last, d + 1, v);
		now++;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(0);
	dfs0(deep);
	int now = deep2;
	while (-1 != deep2) {
		st.insert(deep2);
		deep2 = pre[deep2];
	}
	//cout << deep << endl;
	//cout << deep2 << endl;
	dfs2(deep);
	rep(i, N) {
		cout << a[i] << " ";
	}
	return 0;
}