#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

using Graph = vector<vector<int>>;
int N;
Graph G;

vector<vector<long long>> dp;
long long rec(int v, int p = -1) {
    int s = G[v].size();
    long long res = 0;
    dp[v].assign(s, -1);
    for (int i = 0; i < s; ++i) {
        int to = G[v][i];
        if (to == p) continue;
        dp[v][i] = rec(to, v);
        chmax(res, dp[v][i] + 1);
    }
    return res;
}

void rerec(int v, long long pval = 0, int p = -1) {
    int s = G[v].size();
    for (int i = 0; i < s; ++i) {
        int to = G[v][i];
        if (to == p) {
            dp[v][i] = pval;
            continue;
        }
    }
    vector<long long> left(s+1, -1), right(s+1, -1);
    for (int i = 0; i < s; ++i) {
        left[i+1] = max(left[i], dp[v][i]);
        right[i+1] = max(right[i], dp[v][s-i-1]);
    }
    for (int i = 0; i < s; ++i) {
        int to = G[v][i];
        if (to == p) continue;
        rerec(to, max(left[i], right[s-i-1]) + 1, v);
    }
}

void solve() {
    dp.assign(N, vector<long long>());
    rec(0);
    rerec(0);
    for (int v = 0; v < N; ++v) {
        long long res = 0;
        for (int i = 0; i < G[v].size(); ++i) {
            chmax(res, dp[v][i] + 1);
        }
        cout << (N-1)*2 - res << endl;
    }
}

int main() {
    cin >> N;
    G.assign(N, vector<int>());
    for (int i = 0; i < N-1; ++i) {
        int u, v; cin >> u >> v; --u, --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    solve();
}

