#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
    return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
template<typename T>
ostream& operator << (ostream &i, set<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 1e9;
const ll mod = 1e9 + 7;
vector<vector<int>> g;
vector<int> v;
int v1, v2;
void dfs(int i, int p) {
    v[i] = ~p ? v[p] + 1 : 0;
    v2 = v[i] > v[v2] ? i : v2;
    for (int j : g[i]) if (j != p) dfs(j, i);
}
bool dfs2(int i, int p) {
    if (i == v2) return true;
    for (int j = 0; j < g[i].size(); ++j) if (g[i][j] != p) {
        if (dfs2(g[i][j], i)) {
            swap(g[i][j], g[i].back());
            return true;
        }
    }
    return false;
}
int _t = 1;
void dfs3(int i, int p) {
    v[i] = _t++;
    for (int j : g[i]) if (j != p)
        dfs3(j, i), _t++;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    g.resize(n), v.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y), g[y].push_back(x);
    }
    dfs(0, -1);
    dfs(v1 = v2, -1);
    dfs2(v1, -1);
    dfs3(v1, -1);
    for (int i : v) cout << i << ' ';
}
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

i64 dfs(const vvi &edges, i64 cur, i64 prev, i64 n, const vi &to, vi &ans, bool f) {
  // start from v
  //cerr << "dfs " << cur << " " << prev << " " << n << endl;
  ans[cur] = n;
  for(auto &e: edges[cur]) {
    if(e != prev && e != to[cur]) {
      n += 1;
      n = dfs(edges, e, cur, n, to, ans, false);
      n += 1;
    }
  }
  if(f && to[cur] != -1) {
    n += 1;
    n = dfs(edges, to[cur], cur, n, to, ans, true);
  }
  return n;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;  
  i64 t, T;
  i64 N; cin >> N;
  vvi edges(N);
  REP(0, N-1, i) {
    i64 a, b; RI(a); RI(b);
    --a; --b;
    edges[a].pb(b);
    edges[b].pb(a);
  }

  const i64 INF = N * 2;

  auto bfs = [&](i64 s) {
    vi dists(N, INF);
    vi from(N, -1);
    dists[s] = 0;
    queue<i64> q;
    q.push(s);
    while(!q.empty()) {
      i64 cur = q.front(); q.pop();
      for(auto &e: edges[cur]) {
        if(dists[e] == INF) {
          dists[e] = dists[cur] + 1;
          from[e] = cur;
          q.push(e);
        }
      }
    }
    /*
    for(auto &d: dists) {
      cerr << d << " ";
    }
    cerr << endl;
    for(auto &d: from) {
      cerr << d << " ";
    }
    cerr << endl;
    */
    return pair<vi, vi> {dists, from};
  };

  auto res_0 = bfs(0);
  vi &d0 = res_0.first;
  i64 u = -1;
  REP(0, N, i) {
    if(u == -1 || d0[u] < d0[i]) {
      u = i;
    }
  }
  assert(u != -1);
  auto res_u = bfs(u);
  vi &du = res_u.first;
  vi &fu = res_u.second;
  i64 v = -1;
  REP(0, N, i) {
    if(v == -1 || du[v] < du[i]) {
      v = i;
    }
  }
  assert(v != -1);
  //cerr << "diameter " << du[v] << " " << u << " -> " << v << endl;

  vi ans(N, -1);
  dfs(edges, v, -1, 1, fu, ans, true);
  WVI(ans);

  return 0;
}

