#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;
int x=0;
vector<int> ans;

void dfs(vector<vector<pair<int, int>>> &E, int from, int p){

    for(auto [to, c] : E[from]){
        if (p == to) continue;
        if (c == -1) x++;
        dfs(E, to, from);
    }
}

void dfs2(vector<vector<pair<int, int>>> &E, int from, int p){

    for(auto [to, c] : E[from]){
        if (p == to) continue;
        if (c == 1) ans[to] = ans[from]+1;
        else ans[to] = ans[from]-1;
        dfs2(E, to, from);
    }
}

int main(){

    int N, a, b;
    cin >> N;
    ans.resize(N);
    vector<vector<pair<int, int>>> E(N);
    for (int i=0; i<N-1; i++){
        cin >> a >> b; a--; b--;
        if (a > b) swap(a, b);
        E[a].push_back({b, 1});
        E[b].push_back({a, -1});
    }

    dfs(E, 0, -1);
    ans[0] = x;
    dfs2(E, 0, -1);

    for (int i=0; i<N; i++) cout << ans[i] << endl;

    return 0;
}