#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>
using namespace std;
//dengyaotriangle!

const int maxn=200005;

int n;
vector<int>adj[maxn];
int dp[maxn],dpt[maxn];
int mxv,mu,mv;
void dfs(int u,int f){
    dp[u]=0;dpt[u]=u;
    for(int v:adj[u])if(v!=f){
        dfs(v,u);
        if(dp[u]+dp[v]+1>mxv){
            mxv=dp[u]+dp[v]+1;
            mu=dpt[u];mv=dpt[v];
        }
        if(dp[v]+1>dp[u]){
            dp[u]=dp[v]+1;
            dpt[u]=dpt[v];
        }
    }
}
bool dfs1(int u,int f){
    int id=-1;
    for(int v:adj[u])if(v!=f){
        if(dfs1(v,u)){
            id=v;
        }
    }
    if(id!=-1){
        adj[u].erase(find(adj[u].begin(),adj[u].end(),id));
        adj[u].push_back(id);
    }
    return u==mv||id!=-1;
}
int cnt=0;
int ans[maxn];

void dfs2(int u,int f){
    ans[u]=cnt+1;
    for(int v:adj[u])if(v!=f){
        cnt++;
        dfs2(v,u);
        cnt++;
    }
}
int main(){
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);adj[v].push_back(u);
    }
    mxv=0;mu=mv=1;
    dfs(1,0);
    dfs1(mu,0);
    dfs2(mu,0);
    for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
    return 0;
}