#include <bits/stdc++.h>

#define task "D"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FORD(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; FOR(_, l, r) DB1(A, _); cerr << '\n';}
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vl;
const int N = 2e5 + 2;
int n, par[N], d[N], ans[N];
vi g[N];
int bfs(int r)
{
    queue<int> q;
    fill(d + 1, d + 1 + n, -1);
    d[r] = 0;
    par[r] = 0;
    q.push(r);
    int res = 0;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        res = u;
        for (int v : g[u]) if (d[v] == -1)
        {
            d[v] = d[u] + 1;
            par[v] = u;
            q.push(v);
        }
    }
    return res;
}
bool in[N];
int nn = 1;
void dfs(int u, int p)
{
    ans[u] = nn;
    for (int v : g[u]) if (v != p && (!in[u] || v != par[u]))
    {
        nn++;
        dfs(v, u);
        nn++;
    }
    if (in[u] && par[u])
    {
        nn++;
        dfs(par[u], u);
    }
}

int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n;
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].eb(v);
        g[v].eb(u);
    }
    int ed = bfs(bfs(1));
    for (int u = ed; u; u = par[u]) in[u] = 1;
    dfs(ed, 0);
    FOR(i, 1, n) cout << ans[i] << ' ';
    return 0;
}

#include<bits/stdc++.h> 
#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define endl "\n"

using namespace std;

const int max_n = 2e5+100;
const int off_set = 1e5+5;
const int max_A = 55;
const int Mod = 1e9+7;
const int inf = 2e18;

int n;
vector<int> adj[max_n];

int depth[max_n],dp[max_n];

void dfs(int v,int p,int d){
    depth[v]=d;
    dp[v]=d;

    for(int x:adj[v]) if(x!=p){
        dfs(x,v,d+1);
        dp[v]=max(dp[v],dp[x]+1);
    }

    return;
}

int ans[max_n];
int counter;

void solve(int v,int p){
    ans[v]=counter;

    for(int x:adj[v]) if(x!=p){
        counter++;
        solve(x,v);
        counter++;
    }

}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;x--;y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(0,-1,0);

    int farthest=0;
    for(int i=0;i<n;i++) if(depth[i]>depth[farthest]){
        farthest=i;
    }

    dfs(farthest,-1,0);

    for(int i=0;i<n;i++){
        sort(adj[i].begin(),adj[i].end(),[](const int& a,const int& b)->bool{
            return dp[a]<dp[b];
        });
    }

    solve(farthest,-1);

    for(int i=0;i<n;i++){
        cout<<ans[i]+1<<" ";
    }
    cout<<endl;

}