#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using namespace std;

vector<int> g[101010];
int dist[101010], ans[101010];

void dfs1(int v, int p) {
    for (int u : g[v]) {
        if (u == p) continue;
        dfs1(u, v);
        dist[v] = max(dist[v], dist[u] + 1);
    }
}

void dfs2(int v, int d_p, int p) {
    vector<pair<int, int>> d_c;
    d_c.emplace_back(0, -1);
    for (int &u : g[v]) {
        if (u == p) d_c.emplace_back(d_p + 1, u);
        else d_c.emplace_back(dist[u] + 1, u);
    }
    sort(d_c.rbegin(), d_c.rend());
    ans[v] = d_c[0].first;
    for (int &u : g[v]) {
        if (u == p) continue;
        dfs2(u, d_c[d_c[0].second == u].first, v);
    }
}

int main() {
    int N;
    cin >> N;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(0, -1);
    dfs2(0, 0, -1);
    rep(i, N) {
        cout << (N-1)*2 - ans[i] << endl;
    }
}

