#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
struct Node;
vector<Node> V;
int cnt = 0;
struct Node {
  int idx;
  int d = 0;
  int ans = 0;
  int next = -1;
  vector<int> nbr;
  bool vst = false;
  void dfs(int _d) {
    vst = true;
    d = _d;
    for(int x : nbr) if(!V[x].vst) V[x].dfs(d+1);
  };
  int dfs2(int _t) {
    vst = true;
    for(int x : nbr) if(!V[x].vst) {
      int ret = V[x].dfs2(_t);
      if(ret != -1) next = ret;
    }
    if(idx == _t || next != -1) return idx;
    else return -1;
  }
  void dfs3() {
    vst = true;
    cnt++;
    ans = cnt;
    for(int x : nbr) if(x != next && !V[x].vst) {
      V[x].dfs3();
      cnt++;
    }
    if(next != -1) V[next].dfs3();
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  V = vector<Node>(N);
  REP(i, N) V[i].idx = i;
  REP(i, N-1) {
    int A, B;
    cin >> A >> B;
    A--; B--;
    V[A].nbr.push_back(B);
    V[B].nbr.push_back(A);
  }
  V[0].dfs(0);
  int s = 0;
  int ma = -1;
  REP(i, N) if(V[i].d > ma) {
    ma = V[i].d;
    s = i;
  }
  REP(i, N) V[i].vst = false;
  V[s].dfs(0);
  int t = 0;
  ma = -1;
  REP(i, N) if(V[i].d > ma) {
    ma = V[i].d;
    t = i;
  }
  REP(i, N) V[i].vst = false;
  V[s].dfs2(t);
  REP(i, N) V[i].vst = false;
  V[s].dfs3();
  REP(i, N) cout << V[i].ans << (i!=N-1 ? " " : "");
  cout << "\n";
}
#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
#define ll long long
#define ld long double
#define pii pair < ld , ll >
#define pb push_back

using namespace std;

const ll N = 2e5 + 10;

int n , x , y;
int d[N] , num[N] , dep[N];
vector < int > G[N];

void dfs1(int w , int p)
{
    d[w] = d[p] + 1;

    for(auto i : G[w])
        if(i != p)
            dfs1(i , w);
}

void dfs2(int w , int p)
{
    for(auto i : G[w])
        if(i != p)
        {
            dfs2(i , w);
            dep[w] = max(dep[w] , dep[i] + 1);
        }
}

int cnt = 1;

void dfs3(int w ,  int p)
{
    num[w] = cnt;
    vector < pii > v;

    for(auto i : G[w])
        if(i != p)
            v.pb({dep[i] , i});

    sort(v.begin() , v.end());

    for(auto i : v)
    {
        ++cnt;
        dfs3(i.second , w);
        ++cnt;
    }
}

signed main()
{
	#ifndef ONLINE_JUDGE
		FastIO , FILES;
	#endif

    int i;

    cin >> n;

    for(i = 1 ; i < n ; i++)
    {
        cin >> x >> y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dfs1(1 , 0);

    int mx = 0 , root = 0;

    for(i = 1 ; i <= n ; i++)
        if(mx < d[i])
            mx = d[i] , root = i;

    dfs2(root , 0);
    dfs3(root , 0);

    for(i = 1 ; i <= n ; i++)
        cout << num[i] << ' ';

    return 0;
}
