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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
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(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

const int maxn = 2e5+10;
int N,enCamino[maxn],res[maxn];
vi graph[maxn];

void dfs(int u,int p,int d,int &maxi,int &p1){
	if(d > maxi){
		maxi = d;
		p1 = u;
	}
	for(auto &v : graph[u]){
		if(v == p)continue;
		dfs(v,u,d+1,maxi,p1);
	}
}
int buscaCamino(int u,int p,int fin,vi &path){
	if(u == fin){
		path.pb(u);
		return 1;
	}
	for(auto &v : graph[u]){
		if(v == p)continue;
		if(buscaCamino(v,u,fin,path)){
			path.pb(u);
			return 1;
		}
	}
	return 0;
	
}
void dfs2(int u,int p,int &idx){
	res[u] = idx++;
	for(auto &v : graph[u]){
		if(enCamino[v])continue;
		if(v == p)continue;
		dfs2(v,u,idx);
	}
	idx++;
	
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	forn(i,0,N-1){
		int u,v; cin >> u >> v; u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	int p1 = -1,lenDiameter = -1,p2 = -1;
	dfs(0,0,0,lenDiameter,p1);
	lenDiameter = -1;
	dfs(p1,p1,0,lenDiameter,p2);
	debug(p1+1,p2+1);
	vi camino;
	buscaCamino(p1,p1,p2,camino);
	reverse(all(camino));
	
	for(auto &u : camino)enCamino[u] = 1;
	
	int idx = 1;
	for(auto &u : camino){
		res[u] = idx++;
		for(auto &v : graph[u]){
			if(enCamino[v])continue;
			dfs2(v,v,idx);
		}
		
	}
	debug(camino);
	
	forn(i,0,N)cout << res[i] << ' ';
	cout << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define eb emplace_back
#define mp make_pair
typedef pair<int,int> pii;
#define f first
#define s second

#define min(a,b) ((a<b)?a:b)

//const int mod=1000000007;
bool debug=0;

vector<int> adjl[200005];

int dis[200005],prevv[200005];
pii fur;
void furth(int node,int prev=-1){
  prevv[node]=prev;
  fur=max(fur,mp(dis[node],node));
  //if(debug)cout<<dis[node]<<' '<<node<<"kool\n";
  for(int x:adjl[node]){
    if(x==prev)continue;
    dis[x]=dis[node]+1;
    furth(x,node);
  }
}

bool mark[200005];
int num[200005],cur=1;
void dfs(int node,int prev=-1){
  //if(debug)cout<<"search "<<node<<'\n';
  num[node]=cur++;
  for(int x:adjl[node]){
    if(x==prev)continue;
    if(mark[x])continue;
    dfs(x,node);
  }
  if(mark[node])
    for(int x:adjl[node]){
      if(x==prev)continue;
      if(mark[x]){
        dfs(x,node);break;
      }
    }
  cur++;
}


int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int n,a,b;
  cin>>n;
  for(int i=1;i<n;i++){
    cin>>a>>b;
    adjl[a].push_back(b);
    adjl[b].push_back(a);
  }
  fur=mp(-1,-1);
  dis[1]=1;furth(1);
  a=fur.s;

  fur=mp(-1,-1);
  dis[a]=1;furth(a);
  b=fur.s;
  do{
    mark[b]=true;
    b=prevv[b];
  }while(b!=-1);
  //fur.f=-1;
  //dis[fur.s]=1;furth(fur.s);
  if(debug)cout<<"ENDPoint "<<fur.s<<'\n';
  dfs(a);//one end of diameter...

  for(int i=1;i<=n;i++){
    cout<<num[i];
    if(i<n)cout<<' ';
    else cout<<'\n';
  }
  return 0;
}
/*

*/
