#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define range(i, a, b) for (ll i = (a); i < (b); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pri_b = priority_queue<T>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); }
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T> void er(T a) { cout << a << '\n'; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }
template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

const int N = 200010;
vector<vector<int>> graph(N, vector<int>());
vector<int> xd(N), yd(N);

void dfs(int n, int p, int d, vector<int> &v) {
	v[n] = d;
	for (int i : graph[n]) {
		if (i != p) dfs(i, n, d + 1, v);
	}
}

vector<int> ans(N);

void tour(int n, int p, vector<int> &v) {
	v.pb(n);
	for (int i : graph[n]) {
		if (i != p && ans[i] == 0) {
			tour(i, n, v);
			v.pb(n);
		}
	}
}

int main() {
	int n;
	cin >> n;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	dfs(0, -1, 0, xd);
	int ver = -1; int m = 0;
	rep(i, n) if (chmax(m, xd[i])) ver = i;
	dfs(ver, -1, 0, xd); int rver = 0; m = 0;
	rep(i, n) if (chmax(m, xd[i])) rver = i;
	dfs(rver, -1, 0, yd);
	rep(i, n) {
		int r = -1;
		vector<int> nv;
		for (int nxt : graph[i]) {
			if (yd[nxt] < yd[i]) {
				r = nxt;
			}
			else nv.pb(nxt);
		}
		if (r != -1) nv.pb(r);
		graph[i] = nv;
	}
	vector<int> vec;
	tour(ver, -1, vec);
	rep(i, vec.size()) {
		if (ans[vec[i]] == 0) ans[vec[i]] = i + 1;
	}
	rep(i, n) cout << ans[i] << ' ';
	cout << '\n';
}
//Author: RingweEH
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ll long long
#define db double
using namespace std;
int min( int a,int b ) { return a<b ? a : b; }
int max( int a,int b ) { return a>b ? a : b; }
void bmax( int &a,int b ) { a=(a>b) ? a : b; }
void bmin( int &a,int b ) { a=(a<b) ? a : b; }
const int L=1<<20;
char buf[L],*p1,*p2;
#define getchar() (p1==p2?(p2=buf+fread(p1=buf,1,L,stdin),p1==p2?EOF:*p1++):*p1++)
int read()
{
    int x=0,w=1; char ch=getchar();
    while ( ch>'9' || ch<'0' ) { if ( ch=='-' ) w=-1; ch=getchar(); }
    while ( ch<='9' && ch>='0' ) x=x*10+ch-'0',ch=getchar();
    return x*w;
}

const int N=2e5+10;
//struct Edge{ int to,nxt; }e[N<<1];
int n,dep[N],rt,head[N],tot=1;
int height[N],ans[N],cnt=0;
vector<int> g[N];

void Adde( int u,int v ) { g[u].push_back(v); g[v].push_back(u); }
bool cmp( int x,int y ) { return height[x]<height[y]; }
void DFS( int u,int fat )
{
	for ( int v : g[u] )
		if ( v^fat ) dep[v]=dep[u]+1,DFS(v,u);
}
void DFS2( int u,int fat )
{
	height[u]=0;
	for ( int v : g[u] ) 
		if ( v^fat ) DFS2(v,u),bmax(height[u],height[v]);
	height[u]++;
}
void GetAns( int u,int fat )
{
	ans[u]=++cnt;
	for ( int v : g[u] )
		if ( v^fat ) GetAns(v,u);
	cnt++;
}

int main()
{
//freopen( "exam.in","r",stdin );

	n=read();
	for ( int i=1,u,v; i<n; i++ ) u=read(),v=read(),Adde(u,v);

	DFS(1,0); int tmp=0;
	for ( int i=1; i<=n; i++ ) if ( dep[i]>tmp ) tmp=dep[i],rt=i;
	DFS2(rt,0);
	for ( int i=1; i<=n; i++ ) sort(g[i].begin(),g[i].end(),cmp);
	GetAns(rt,0);

	for ( int i=1; i<=n; i++ ) printf("%d ",ans[i] );

	return 0;
}