#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
const double PI = acos(-1);
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}
v<v<ll>> adj;
v<ll> d, p;
ll bfs(ll s) {
	queue<ll> q;
	v<ll> used(n, 0);
	d.assign(n, inf);
	p.assign(n, -1);
	q.push(s);
	used[s] = 1;
	d[s] = 0;
	while (!q.empty())
	{
		ll V = q.front();
		q.pop();
		for (ll u : adj[V])
		{
			if (!used[u])
			{
				used[u] = 1;
				q.push(u);
				d[u] = d[V] + 1;
				p[u] = V;
			}
		}
	}
	ll mx = 0;
	ll  pos = -1;
	for (int i = 0; i < n; i++) {
		if (d[i] > mx) {
			mx = d[i];
			pos = i;
		}
	}
	return pos;
}

v<ll> out, todo;
ll cntr = 1;
void dfs(ll s, ll p, ll t) {
	out[s] = cntr++;
	for (auto u : adj[s]) {
		if (u != p && todo[u] == 0) {
			dfs(u, s, t);
		}
	}
	for (auto u : adj[s]) {
		if (u != p && todo[u] == 1) dfs(u, s, t);
	}
	cntr++;
}
int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n;
	out.resize(n);
	todo.assign(n, 0);
	adj.resize(n);
	rep(i, n - 1) {
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	ll s = bfs(0);

	t = bfs(s);
	x = t;
	while (x != -1) {
		todo[x] = 1;
		x = p[x];
	}
	dfs(s, -1, t);
	rep(i, n) {
		cout << out[i] << ' ';
	}

	return 0;



}



#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> dist;
std::vector<int> stack;
std::vector<int> stack_res;
void dfs0(int i, int prev, int goal = -1) {
	stack.push_back(i);
	if (i == goal) stack_res = stack;
	for (auto j : hen[i]) if (j != prev) {
		dist[j] = dist[i] + 1;
		dfs0(j, i, goal);
	}
	stack.pop_back();
}

int cnt = 0;
std::vector<int> res;
std::vector<int> avoid;

void dfs1(int i, int prev) {
	res[i] = cnt;
	for (auto j : hen[i]) if (j != prev) {
		if (avoid[i] == j) continue;
		cnt++;
		dfs1(j, i);
		cnt++;
	}
	for (auto j : hen[i]) if (j != prev) {
		if (avoid[i] != j) continue;
		cnt++;
		dfs1(j, i);
		cnt++;
	}
}

int main() {
	int n = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	dist.assign(n, 0);
	dfs0(0, -1);
	int t0 = std::max_element(dist.begin(), dist.end()) - dist.begin();
	dist.assign(n, 0);
	dfs0(t0, -1);
	int t1 = std::max_element(dist.begin(), dist.end()) - dist.begin();
	
	dist.assign(n, 0);
	
	dfs0(t0, -1, t1);
	
	auto tmp = stack_res;
	avoid.resize(n, -1);
	for (int i = 0; i + 1 < (int) tmp.size(); i++) avoid[tmp[i]] = tmp[i + 1];
	
	/*
	for (auto i : tmp) std::cerr << i << std::endl;
	*/
	res.resize(n);
	dfs1(tmp[0], -1);
	
	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", res[i] + 1);
	}
	puts("");
	
	return 0;
}
