#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<pll> vpll;
template<typename T> void makeunique(vector<T> &vx) {sort(vx.begin(),vx.end());auto it=unique(vx.begin(),vx.end());vx.resize(std::distance(vx.begin(),it));}
const int mn=200000+4;

ll dfs(vvi const & tree, int u, int p, int depth) {
  ll res = ((ll) depth << 32) + u;
  for (int v : tree[u]) {
          if (v != p) {
            res = max(res, dfs(tree, v, u, depth + 1));
          }
  }
  return res;
}

pii diameter(vvi const & tree) {
  int furthestVertex = (int) dfs(tree, 1, -1, 0);
  return MP((int) (dfs(tree, furthestVertex, -1, 0)), furthestVertex);
}


vi order;
vvi g;
bitset<mn> special;
int id=1;
void go(int x, int p) {
  order[x]=id;
  ++id;
  for (auto &y:g[x]) {
    if (y==p) continue;
    go(y,x);
  }
  if (!special[x]) {
    ++id;
  }
}

vi vpar;
void makepar(int x, int p) {
  vpar[x]=p;
  for (auto &y:g[x]) {
    if (y==p) continue;
    makepar(y,x);
  }
}


int getdist(int x, int p, int dest) {
  if (x==dest) return 0;
  for (auto &y:g[x]) {
    if (y==p) continue;
    int got=getdist(y,x,dest);
    if (got!=-1) return got+1;
  }
  return -1;
}


void solve(long long n, std::vector<long long> A, std::vector<long long> B){
  g.resize(n+1); vpar.resize(n+1); order.resize(n+1);
  for (int i=0;i<A.size();i++) {
    int x=A[i],y=B[i];
    g[x].PB(y);
    g[y].PB(x);
  }
  pii diam=diameter(g);
  int src=diam.fst,dest=diam.snd;
  makepar(src,-1);
  //printf("src:%d dest:%d\n",src,dest);
  {
    int x=dest;
    while(x!=-1) {
      //printf("x:%d\n",x);
      special[x]=true;
      x=vpar[x];
    }
  }
  for (int x=1;x<=n;x++) sort(g[x].begin(),g[x].end(),[&](int x,int y) {return MP(special[x],x) < MP(special[y],y);} );
  go(src,-1);
  for (int x=1;x<=n;x++) printf("%d ",order[x]);
  printf("\n");
  //for (int x=1;x<=n;x++) for (int y=1;y<=n;y++) {
  //  if (abs(order[x]-order[y]) < getdist(x,-1,y)) {
  //    printf("x:%d y:%d order:%d %d dist:%d\n",x,y,order[x],order[y],getdist(x,-1,y));fflush(stdout);
  //    assert(0);
  //  }
  //}
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-1);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int n,c;
vi d,out;
vvi G;
void dfs(int a,int p,int t){
	d[a]=t;
	for(auto i:G[a]){
		if(i==p)continue;
		dfs(i,a,t+1);
	}
}
void dfs2(int a,int p){
	out[a]=c;
	for(auto i:G[a]){
		if(d[i]<d[a])continue;
		if(i==p)continue;
		c++;
		dfs2(i,a);
		c++;
	}
	for(auto i:G[a]){
		if(d[i]>d[a])continue;
		if(i==p)continue;
		c++;
		dfs2(i,a);
		c++;
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	out=d=vi(n,-1);
	dfs(0,-1,0);
	int r,ma=0;
	rep(i,n)cmax(ma,d[i]);
	rep(i,n)if(ma==d[i]){
		r=i;
	}
	d=vi(n,-1);
	c=1;
	dfs(r,-1,0);
	ma=0;
	rep(i,n)cmax(ma,d[i]);
	rep(i,n)if(ma==d[i]){
		r=i;
	}

	dfs2(r,-1);
	show1d(out);
}
