// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
// #pragma GCC optimize("-Ofast","-funroll-all-loops")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include <unordered_set>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rg register
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
#define ALL(x) x.begin(),x.end()
const long long INF = 2e18; //0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-10;
void err(){puts("");}
template<typename T,typename... Args>void err(const T& arg,const Args&... args){
    std::cout << arg << ' ';
    err(args...);
}
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}
template<typename T>void chmax(T& a,T b){
    if (b > a)
        a = b;
}
template<typename T>void chmin(T& a,T b){
    if (b < a)
        a = b;
}
#ifdef LOCAL
#define dbg(x...) do{std::cout<<#x<<" -> ";err(x);}while(0)
FILE *_INPUT = freopen("input.txt", "r", stdin);
// FILE *_OUTPUT = freopen("output.txt", "w", stdout);
#else
#define dbg(x...) ;
#endif
using namespace std;
const int maxn = 2e5 + 10;
const int DEG = 20;
int fa[maxn][20];
int deep[maxn], son[maxn], len[maxn];
vector<int> G[maxn];
int lca(int u,int v)
{
    if (deep[u] < deep[v])
        swap(u, v);
    int x = deep[u] - deep[v];
    for (int i = 0; i < DEG && x; ++i)
    {
        if (x & 1)
            u = fa[u][i];
        x >>= 1;
    }
    if (u == v)
        return u;
    for (int i = 0; i < DEG; ++i)
    {
        if (fa[u][i] == fa[v][i])
            continue;
        u = fa[u][i];
        v = fa[v][i];
    }
    return fa[u][0];
}

void dfs(int u, int pre)
{
    son[u] = 0;
    len[u] = 0;
    deep[u] = deep[pre] + 1;
    fa[u][0] = pre;
    for (int i = 1; i < DEG; ++i)
    {
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    }
    for (int v : G[u])
    {
        if (v == pre)
            continue;
        dfs(v, u);
        len[u] = max(len[u], len[v] + 1);
        if (len[v] > len[son[u]])
            son[u] = v;
    }
}
ll ans[maxn];
int las = 0;
void dfs2(int u, int pre)
{
    ans[u] = ans[las] + deep[u] + deep[las] - 2 * deep[lca(u, las)];
    las = u;
    for (int v : G[u])
    {
        if (v == pre || v == son[u])
            continue;
        dfs2(v, u);
    }
    if(son[u])
        dfs2(son[u], u);
}

int main()
{
    int n;
    int u, v;
    read(n);
    for (int i = 1; i < n; ++i)
    {
        read(u, v);
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    dfs(1, 0);
    int R = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (deep[i] > deep[R])
            R = i;
    }
    dfs(R, 0);
    dfs2(R, 0);
    for (int i = 1; i <= n; ++i)
        printf("%lld%c", ans[i], " \n"[i == n]);
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n;
vector<vector<int>> e;
P longest(int v, int per){
	P mx=P(0, v);
	for(int u : e[v]) if(u!=per){
		P p=longest(u, v);
		mx=max(mx, P(p.first+1, p.second));
	}
	return mx;
}

vector<int> p;
void setp(int v, int per){
	p[v]=per;
	for(int u : e[v]) if(u!=per) setp(u, v);
}

vector<int> ans;
int c;
void setans(int v, int per){
	ans[v]=c++;
	if(p[v]==-1) return;
	for(int u : e[v]) if(u!=per && u!=p[v]) setans(u, v);
	if(p[v]!=per) setans(p[v], v);
	c++;
}

int main(){
	cin>>n;
	e=vector<vector<int>>(n);
	rep(i, n-1){
		int a, b;
		cin>>a>>b; a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	int a=longest(0, -1).second;
	int b=longest(a, -1).second;

	p=vector<int>(n, -1);
	setp(a, -1);

	ans=vector<int>(n);
	c=1;
	setans(b, -1);

	for(int e : ans) cout<<e<<" ";
	cout<<endl;
	return 0;
}
