#include<bits/stdc++.h>
using namespace std;

using i64 = int64_t;

struct Edge{
    int from, to, cost;
};

using Graph = vector<vector<Edge>>;
using Weight = int;

constexpr Weight INF = 1e9;

tuple<int, int, Weight> tree_diameter(const Graph &tree){
    struct {
        pair<Weight, int> operator()(int v, const Graph &tree){
            pair<Weight, int> res(0, v);
            vector<Weight> dist(tree.size(), INF);
            dist[v] = 0;
            queue<pair<Weight, int>> que;
            que.push({0, v});
            while(!que.empty()){
                auto cur = que.front(); que.pop();
                res = max(res, cur);
                for(auto e: tree[cur.second]){
                    Weight new_cost = cur.first + e.cost;
                    if(new_cost >= dist[e.to])continue;
                    dist[e.to] = new_cost;
                    que.push({new_cost, e.to});
                }
            }
            return res;
        }
    } find_farthest_node;

    auto r = find_farthest_node(0, tree);
    auto t = find_farthest_node(r.second, tree);
    return make_tuple(r.second, t.second, t.first);
}

void bfs(int s, vector<Weight> &v, const Graph &tree){
    v[s] = 0;
    queue<pair<Weight, int>> que;
    que.push({0, s});
    while(!que.empty()){
        auto cur = que.front(); que.pop();
        for(auto e: tree[cur.second]){
            Weight new_cost = cur.first + e.cost;
            if(new_cost >= v[e.to])continue;
            v[e.to] = new_cost;
            que.push({new_cost, e.to});
        }
    }
}

int main(){
    int n;
    cin >> n;
    Graph tree(n, vector<Edge>());
    for(int i=0;i<n-1;++i){
        int u, v;
        cin >> u >> v;
        u--; v--;
        tree[u].push_back({u, v, 1});
        tree[v].push_back({v, u, 1});
    }
    int u, v, d;
    tie(u, v, d) = tree_diameter(tree);
    vector<Weight> ud(n, INF), vd(n, INF);
    bfs(u, ud, tree);
    bfs(v, vd, tree);
    for(int i=0;i<n;++i){
        cout << 2*(n-1) - max(ud[i], vd[i]) << endl;
    }

    return 0;
}

