#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
const int N = 200005;
int d[N] = { 0 }, ans[N] = { 0 }, id2 = 0, tol = 0;
bool u[N] = { 0 };
vector<int> my[N];

void dfs(int x) {
    int i = 0, y = 0;
    for (i = 0; i < my[x].size(); i ++) {
        y = my[x][i];
        if (d[y]) continue;
        d[y] = d[x] + 1;
        dfs(y);
    }
}
void dfs2(int x) {
    int i = 0, y = 0;
    for (i = 0; i < my[x].size(); i ++) {
        y = my[x][i];
        if (d[y]) continue;
        d[y] = d[x] + 1;
        dfs2(y);
        if (u[y]) u[x] = true;
    }
    if (x == id2) u[x] = true;
}

void dfs3(int x) {
    ans[x] = ++ tol;
    int s = 0, i = 0, y = 0;
    for (i = 0; i < my[x].size(); i ++) {
        y = my[x][i];
        if (d[y]) continue;
        if (u[y]) {
            s = y;
            continue;
        }
        d[y] = d[x] + 1;
        dfs3(y);
        ++ tol;
    }
    if (s) {
        d[s] = d[x] + 1;
        dfs3(s);
        ++ tol;
    }
}
        
void solve() {
    int i = 0, n = 0, id = 0, p = 0, q = 0;
    scanf("%d", &n);
    for (i = 1; i < n; i ++) {
        scanf("%d%d", &p, &q);
        my[p].push_back(q);
        my[q].push_back(p);
    }
    d[1] = 1;
    dfs(1);
    id = 1;
    for (i = 2; i <= n; i ++) {
        if (d[i] > d[id]) id = i;
    }
    memset(d, 0, sizeof(d));
    d[id] = 1;
    dfs(id);
    id2 = 1;
    for (i = 2; i <= n; i ++) {
        if (d[i] > d[id2]) id2 = i;
    }
    memset(d, 0, sizeof(d));
    memset(u, 0, sizeof(u));
    d[id] = 1;
    dfs2(id);
    
    memset(d, 0, sizeof(d));
    d[id] = 1;
    dfs3(id);
    
    for (i = 1; i <= n; i ++) {
        printf("%d", ans[i]);
        if (i < n) printf(" ");
        else printf("\n");
    }
    
}

int main() {
    int o = 1;
    //scanf("%d", &o);
    while (o --) {
        solve();
        //fflush(stdout);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

vector<int> v[211111];
int d[211111],n;

P dfs(int x,int t) {
  d[x]=t;P p=P(d[x],x);
  rep(i,v[x].size())if(d[v[x][i]]==MAX)p=max(p,dfs(v[x][i],t+1));
  return p;
}

P calc() {
  fill(d,d+211111,MAX);P p=dfs(0,0);
  fill(d,d+211111,MAX);P q=dfs(p.S,0);
  return P(p.S,q.S);
}

P pp;
set<ll> s;
ll dfs2(int x,int p) {
  if(x==pp.S) {
    s.in(x);
    return 1;
  }
  ll f=0;
  rep(i,v[x].size()) {
    ll y=v[x][i];
    if(y==p) continue;
    f|=dfs2(y,x);
  }
  if(f) s.in(x);
  return f;
}

ll a[222222],k=1;

void dfs3(ll x,ll p) {
  a[x]=k++;
  ll z=-1;
  rep(i,v[x].size()) {
    ll y=v[x][i];
    if(y==p) continue;
    if(s.count(y)) {
      z=y;
      continue;
    }
    dfs3(y,x);
    k++;
  }
  if(z!=-1) {
    dfs3(z,x);
    k++;
  }
}

void Main() {
  R n;
  rep(i,n-1) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  pp=calc();
  dfs2(pp.F,-1);
  dfs3(pp.F,-1);
  PR(a,n);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
