#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

void debug_out(){
    cerr << endl;
}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef local
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...) 55
#endif

#define all(x) x.begin(), x.end()
const int N = 2e5 + 5;
vector<int> E[N];
int dep[N], ans[N], mx[N], t;
void dfs(int u, int pre){
	mx[u] = dep[u];
	for(int& v: E[u]){
		if(v == pre) continue;
		dep[v] = dep[u] + 1;
		dfs(v, u);
		mx[u] = max(mx[u], mx[v]);
	}
}
void dfs1(int u, int pre){
	sort(all(E[u]), [&](int x, int y){
		return mx[x] < mx[y];
	});
	ans[u] = ++t;
	for(int& v: E[u]){
		if(v != pre) dfs1(v, u);
	}
	++t;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for(int i = 1, u, v; i < n; i++){
		cin >> u >> v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1, 0);
	int x = 1;
	for(int i = 1; i <= n; i++) if(dep[x] < dep[i]) x = i;
	dep[x] = 0;
	dfs(x, 0);
	dfs1(x, 0);
	for(int i = 1; i <= n; i++) cout << ans[i] << ' ';
	return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int qmax(int a, int b){
	return (a > b) ? a : b;
}

int n;
vector<int> v[200200];
vector<int> ord;
int ans[200200];
int nowans = 1;
int pos[200200];
int dept[200200];
int mx_dept[200200];
bool cmp(int a, int b){
	return (mx_dept[a] < mx_dept[b]);
}
void get_dept(int now, int par){
	mx_dept[now] = dept[now];
	rep(i, (int)v[now].size()){
		if(v[now][i] != par){
			dept[v[now][i]] = dept[now] + 1;
			get_dept(v[now][i], now);
			mx_dept[now] = qmax(mx_dept[now], mx_dept[v[now][i]]);
		}
	}
}
int rt;

void dfs(int now, int par){
	ans[(int)ord.size()] = nowans;
	ord.push_back(now);
	sort(v[now].begin(), v[now].end(), cmp);
	rep(i, (int)v[now].size()){
		if(v[now][i] != par){
			nowans++;
			dfs(v[now][i], now);
		}
	}
	nowans++;
}

int main(){
	ios::sync_with_stdio(false); 
	cin >> n;
	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		a--, b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	get_dept(0, -1);
	rt = 0;
	rep(i, n) if(dept[i] > dept[rt]) rt = i;
	memset(dept, 0, sizeof(dept)), memset(mx_dept, 0, sizeof(mx_dept));
	get_dept(rt, -1);
	dfs(rt, -1);
	rep(i, n) pos[ord[i]] = ans[i];
	rep(i, n) cout << pos[i] << " ";
	cout << endl;
	return 0;
}