#include <bits/stdc++.h>

#ifdef HOME
#define db(x) cerr << #x << " = " << x << endl
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define dbv(a) cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

using namespace std;
typedef long long ll;
typedef double dbl;


const int INF = 1.01e9;


struct item {
    int key, prior;
    int sum, val;

    item * l, * r;
    item() { }
    item (int key, int prior) : key(key), prior(prior), l(NULL), r(NULL) { }
};
typedef item * pitem;

int sum(pitem t) {
    return t ? t->sum : 0;
}

void upd_cnt (pitem t) {
    if (t) {
        t->sum = t->val + sum(t->l) + sum(t->r);
    }
}

void split (pitem t, int key, pitem & l, pitem & r) {
    if (!t)
        l = r = NULL;
    else if (key < t->key)
        split (t->l, key, l, t->l),  r = t;
    else
        split (t->r, key, t->r, r),  l = t;
    upd_cnt(l);
    upd_cnt(r);
}

void merge (pitem & t, pitem l, pitem r) {
    if (!l || !r)
        t = l ? l : r;
    else if (l->prior > r->prior)
        merge (l->r, l->r, r),  t = l;
    else
        merge (r->l, l, r->l),  t = r;
    upd_cnt(t);
}

pitem unite (pitem l, pitem r) {
    if (!l || !r)  return l ? l : r;
    if (l->prior < r->prior)  swap (l, r);
    pitem lt, rt;
    split (r, l->key, lt, rt);
    l->l = unite (l->l, lt);
    l->r = unite (l->r, rt);
    upd_cnt(l);
    return l;
}

struct Set {
    pitem t;
};

Set merge(Set s1, Set s2) {
    Set st;
    st.t = unite(s1.t, s2.t);
    return st;
}

int count(Set st, int x) {
    pitem t1 = 0, t2 = 0;
    split(st.t, x, t1, t2);
    int res = sum(t1);
    merge(st.t, t1, t2);
    return res;
}

void print(vector<int> v) {
    for (int x : v) printf("%d ", x);
    printf("\n");
}

//mt19937 rnd(5453);

vector<int> solve(vector<pair<int, int>> ed) {
    int n = ed.size() + 1;
    vector<vector<int>> e(n);
    for (auto o : ed) {
        e[o.first].push_back(o.second);
        e[o.second].push_back(o.first);
    }

    vector<int> dp(n);

    function<Set(int, int, int)> dfs1 = [&](int v, int pr, int mn) {
        Set st;
        st.t = 0;

        for (int to : e[v]) {
            if (to == pr) continue;
            Set nw = dfs1(to, v, max(mn, v));
            dp[to] = count(nw, mn);
            st = merge(st, nw);
        }
        pitem t1 = 0, t2 = 0;
        split(st.t, v, t1, t2);
        pitem tt = new item(v, rand());
        tt->val = sum(t1) + 1;
        upd_cnt(tt);
        st = Set({unite(tt, t2)});
        return st;
    };
    dfs1(0, -1, 0);

    //print(dp);
    vector<int> ans(n);
    function<void(int, int, int, int)> dfs2 = [&](int v, int pr, int sum, int h) {
        for (int to : e[v]) {
            if (to == pr) continue;
            sum += dp[to];
        }
        ans[v] = sum + h;
        for (int to : e[v]) {
            if (to == pr) continue;
            dfs2(to, v, sum - dp[to], h + 1);
        }
    };
    dfs2(0, -1, 0, 0);
    ans.erase(ans.begin());
    return ans;
}

vector<int> slow(vector<pair<int, int>> ed) {
    int n = ed.size() + 1;
    vector<vector<int>> e(n);
    for (auto o : ed) {
        e[o.first].push_back(o.second);
        e[o.second].push_back(o.first);
    }

    vector<int> ans;
    for (int s = 1; s < n; s++) {
        vector<char> vis(n);
        vis[s] = 1;
        set<int> st;
        for (int to : e[s]) if (!vis[to]) st.insert(to);

        int res = 0;
        while (1) {
            int u = *st.begin();
            st.erase(u);
            vis[u] = 1;
            res++;
            if (u == 0) break;
            for (int to : e[u]) if (!vis[to]) st.insert(to);
        }
        ans.push_back(res);
    }
    return ans;
}

void stress() {
    for (int it = 2764;; it++) {
        cerr << it << endl;
        srand(it);

        int n = rand() % 5 + 2;
        vector<pair<int, int>> ed;
        for (int i = 0; i < n-1; i++) {
            int u = rand() % (i + 1);
            ed.push_back({u, i + 1});
        }
        vector<int> p(n);
        iota(p.begin(), p.end(), 0);
        random_shuffle(p.begin(), p.end());
        for (auto &o : ed) {
            o.first = p[o.first];
            o.second = p[o.second];
        }

        auto ans1 = solve(ed);
        auto ans2 = slow(ed);

        if (ans1 != ans2) {
            print(ans1);
            cout << "instead" << endl;
            print(ans2);
            cout << "----" << endl;
            cout << n << endl;;
            for (auto o : ed) cout << o.first << " " << o.second << endl;
            exit(0);
        }
    }
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
    //stress();

    int n;
    while (scanf("%d", &n) == 1) {
        vector<pair<int, int>> ed(n - 1);
        for (int i = 0; i < n - 1; i++) {
            scanf("%d%d", &ed[i].first, &ed[i].second);
            ed[i].first--;
            ed[i].second--;
        }

        print(solve(ed));
    }

#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 47104