// #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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
int n;
vc<vc<int>> e;

pair<int, int> farthest(int i, int par = -1){
    pair<int, int> ret {0, i};
    for(const int &j : e[i]){
        if(j == par) continue;
        auto next = farthest(j, i);
        next.first ++;
        Maxi(ret, next);
    }
    return ret;
}

vc<int> longest(int s, int t, int par = -1){
    if(s == t) return {s};
    for(const int &i : e[s]){
        if(i == par) continue;
        auto p = longest(i, t, s);
        if(!p.empty()){
            p.push_back(s);
            return p;
        }
    }
    return {};
}

vc<int> ans;
vc<int> path;
int v = 1;
void assign(int i, int depth = 0, int par = -1){
    ans[i] = v;
    for(const int &j : e[i]){
        if(j == par || (depth != -1 && j == path[depth+1])) continue;
        v ++;
        assign(j, -1, i);
        v ++;
    }
    if(depth != -1 && depth < path.size()-1){
        v ++;
        assign(path[depth+1], depth+1, i);
        // v ++;
    }
}

int main(){
    cin >> n;
    e = vc<vc<int>>(n);
    ans = vc<int>(n);
    
    Rep(n-1){
        Cin(int, a, b); a--, b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int s = farthest(0).second;
    int t = farthest(s).second;
    path = longest(t, s);
    assign(s);
    Couts(ans);
}
