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

#define Mod(x) (x>=P)&&(x-=P)
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=hd[a];i;i=nxt[i])

typedef long long ll;
void Max(int &x,int y){(x<y)&&(x=y);}
void Min(int &x,int y){(x>y)&&(x=y);}

bool vio;
char IO;
int rd(int res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const int M=1e6+10;
int nxt[M<<1],to[M<<1],hd[M],ecnt;
void Add(int a,int b){
	nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b;
}
int Mx,tp,bot,L[M],R[M],n;
void dfs(int x,int f,int d){
	static int tot;
	if(d>Mx)tp=x,Mx=d;
	L[x]=++tot;
	erep(i,x){
		int y=to[i];
		if(y==f)continue;
		dfs(y,x,d+1);
	}
	R[x]=tot;
}
bool FA(int a,int b){
	return L[a]<=L[b]&&L[b]<=R[a];
}
int nw=1,ans[M];
void redfs(int x,int f){
	ans[x]=nw;
	erep(i,x){
		int y=to[i];
		if(y==f||FA(y,tp))continue;
		nw++,redfs(y,x);
	}
	erep(i,x){
		int y=to[i];
		if(y!=f&&FA(y,tp))nw++,redfs(y,x);
	}
	nw++;
}
bool let;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	rep(i,2,n=rd()){
		int a=rd(),b=rd();
		Add(a,b),Add(b,a);
	}
	Mx=0,dfs(1,0,0);
	bot=tp,Mx=0,dfs(tp,0,0);	
	ans[1]=1;
	redfs(bot,0);
	rep(i,1,n)printf("%d ",ans[i]);
}

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n, x, y;
vector<vector<int>> edges;
int p = 0, pdist = 0;
bool path[200010];
int ans[200010];
int val = 1;

void dfs(int u, int fa, int dist) {
    if (dist > pdist) {
        p = u;
        pdist = dist;
    }
    for (int v: edges[u]) {
        if (v != fa) {
            dfs(v, u, dist + 1);
        }
    }
}

bool dfs2(int u, int fa) {
    if (u == p) {
        return path[u] = true;
    }
    for (int v: edges[u]) {
        if (v != fa) {
            dfs2(v, u);
            path[u] |= path[v];
        }
    }
    return path[u];
}

void dfs3(int u, int fa) {
    ans[u] = val;
    for (int v: edges[u]) {
        if (v != fa && !path[v]) {
            ++val;
            dfs3(v, u);
            ++val;
        }
    }
    for (int v: edges[u]) {
        if (v != fa && path[v]) {
            ++val;
            dfs3(v, u);
        }
    }
}

inline void work() {
    cin >> n;
    edges.resize(n + 1);
    for (int i = 1; i < n; ++i) {
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    // u-v is the diameter
    dfs(1, 0, 0);
    int u = p;
    pdist = 0;
    dfs(p, 0, 0);
    int v = p;
    dfs2(u, 0);
    dfs3(u, 0);

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

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}