// AtCoder Templete

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define lloop(i, r, n) for (int i = (r) - 1; i >= 0; i--)
#define all(in) in.begin(),in.end()
#define pb push_back
#define fi first
#define se second
#define re resize
#define as assign
#define cl clear

template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using dd = double;
using ldd = long double;

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<dd,dd>;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

using vb = vector<bool>;
using vs = vector<string>;
using vdd = vector<dd>;
using vldd = vector<ldd>;

using pq = priority_queue<int, vector<int>, less<int>>; // 降順に取り出す
using pqq = priority_queue<int, vector<int>, greater<int>>; // 昇順に取り出す

int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll inf = 4e18;

const int MAX = 300300;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1; // 階乗
    finv[0] = finv[1] = 1; // 階乗の逆元
    inv[1] = 1; // 逆元
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = ( MOD - inv[MOD%i] * (MOD/i) % MOD ) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long PER(int n, int k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * finv[n - k] % MOD;
}

ll modpow(ll a, ll n, ll p) {
    ll res = 1;
    while (n) {
        if (n & 1) res = res * a % p;
        a = a * a % p;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a, ll p) { return modpow(a, p-2, p); }

vector<pair<ll,ll>> prime(ll n) {
    vector<pair<ll,ll>> res;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        ll count = 0;
        while (n % i == 0) { count++; n /= i; }
        res.push_back( make_pair(i,count) );
    }
    if (n != 1) res.push_back( make_pair(n,1) );
    return res;
}

int n;
vvi g;
vi path;
vi check;
vi ans;
int num;

pii dfs1(int v, int p) {
    pii res = pii(0,v);
    for ( auto nv : g[v] ) if ( nv != p ) {
        auto ch = dfs1(nv, v);
        ch.fi++;
        chmax( res, ch );
    }
    return res;
}

bool dfs2(int v, int p, int t) {
    bool ch = false;
    if ( v == t ) ch = true;
    for ( auto nv : g[v] ) if ( nv != p && dfs2(nv, v, t) ) ch = true;
    if ( ch || v == t ) path.pb(v);
    return ch; 
}

void dfs3(int v, int p) {
    ans[v] = ++num;
    for ( auto nv : g[v] ) if ( nv != p && nv != check[v] ) dfs3(nv, v);
    if ( check[v] >= 0 ) dfs3(check[v], v);
    ++num;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << fixed << setprecision(10) <<  << endl;
    COMinit();
    
    /* write code under here */
    cin >> n;

    g.re(n);
    rep(i,n-1) {
        int s, t; cin >> s >> t;
        s--; t--;
        g[s].pb(t);
        g[t].pb(s);
    }

    auto p = dfs1(0, -1);
    auto q = dfs1(p.se, -1);

    dfs2(p.se, -1, q.se);
    reverse(all(path));

    check.as(n,-1);
    rep(i,(int)path.size()) if ( i ) check[ path[i-1] ] = path[i];

    ans.as(n,-1);
    num = 0;
    dfs3(p.se, -1);

    for ( auto v : ans ) cout << v << " ";
    cout << endl;
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

const int O = 2e5 + 1;

int t = 1;

vector <int> c, dp, g[O], Max;

int dfs(int u, int par = 0){
    Max[u] = 1;
    for (int v : g[u]){
        if (v == par) continue;
        dp[v] = dp[u] + 1;
        Max[u] = max(Max[u], dfs(v, u) + 1);
    }
    return Max[u];
}

void dfs1(int u, int par = 0){
    c[u] = t;
    vector <pair <int, int>> m;
    for (int v : g[u]){
        if (v == par) continue;
        m.push_back({Max[v], v});
    }
    sort(m.begin(), m.end());
    for (pair <int, int> v : m){
        t += 1;
        dfs1(v.second, u);
        t += 1;
    }
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    c.resize(n + 1);
    dp.resize(n + 1);
    Max.resize(n + 1);
    for (int i = 1; i < n; ++ i){
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    int compare = 0;
    int root = 1;
    for (int i = 1; i <= n; ++ i){
        if (dp[i] > compare){
            compare = dp[i];
            root = i;
        }
    }
    dfs(root);
    dfs1(root);
    for (int i = 1; i <= n; ++ i) cout << c[i] << " ";
}
