#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pii pair<int,int>
#define mkp make_pair

int N;
vector<int> rvs[202020];
int prv[202020];
vector<int> chrvs[202020];

int rt[202020];
int mxp[202020];

int mk[202020];
int ct[202020];

int tl1[202020];
int tl2[202020];
int anss[202020];

int i,j,h;


int main(){
    scanf("%d", &N);
    fornum(i,1,N){
        int a, b;
        scanf("%d%d",&a,&b);
        rvs[a].push_back(b);
        rvs[b].push_back(a);
    }

    prv[1] = 1;
    stack<pii> rs;
    rs.push(mkp(1,0));
    while(!rs.empty()){
        auto r=rs.top();
        rs.pop();
        fornum(i,r.second,rvs[r.first].size()){
            int n = rvs[r.first][i];
            if(prv[r.first]!=n){
                prv[n] = r.first;
                mxp[n] = r.first > mxp[r.first] ? r.first : mxp[r.first];
                chrvs[r.first].push_back(n);
                rs.push(mkp(r.first, i+1));
                rs.push(mkp(n, 0));
                break;
            }
        }
    }

    queue<int> rq;
    /*
    fornum(i,1,N){
        ct[i + 1] = chrvs[i + 1].size();
        if(ct[i+1]==0){
            rq.push(i + 1);
        }
    }*/
    rs.push(mkp(1, 0));
    while(!rs.empty()){
        auto r = rs.top();
        rs.pop();
        if(r.second==chrvs[r.first].size()){
            int n = r.first;
            tl1[n]++;
            //printf("%d:%d:%d ", n, c,mxp[mxp[n]]);
            if(n<mxp[prv[n]]){
                if(n>mxp[mxp[n]]){
                    //printf("d%d:%dfff", n,prv[n]);
                    tl2[prv[n]]+=tl1[n];
                }else{
                    tl1[prv[n]] += tl1[n];
                }
                tl1[n] = 0;
            }
            if(mxp[n]==prv[n]){
                tl1[n] += tl2[n];
            }else{
                tl2[prv[n]] += tl2[n];
            }
            \
            //tl1[n] += tl2[n];
            //tl1[prv[n]] -= tl2[n];
            continue;
        }
        int n = chrvs[r.first][r.second];
        rs.push(mkp(r.first, r.second + 1));
        rs.push(mkp(n, 0));
        //rs2.push(mxp[n] != mxp[r.first] ? n : rs2.top());
        //printf("%d:%d ", n, rs2.top());
    }
    /*
    while(!rq.empty()){
        auto r = rq.front();
        rq.pop();
        tl1[r]++;
        if(r<mxp[prv[r]]){
            tl1[prv[r]]+=tl1[r];
            if(mxp[mxp[prv[r]]]!=1&&r>mxp[mxp[prv[r]]]){
                tl2[prv[r]] += tl1[r];
            }
            tl1[r]=0;
        }
        if()
        tl1[r] += tl2[prv[r]];

        ct[prv[r]]--;
        if(ct[prv[r]]==0){
            rq.push(prv[r]);
        }
    }*/
    /*
    fornum(i,0,N){
        printf("%d ",tl1[i+1]);
    }
    printf("\n");
*/
    rs.push(mkp(1,0));
    while(!rs.empty()){
        auto r=rs.top();
        rs.pop();
        if(r.second==chrvs[r.first].size()){
            continue;
        }
        int n = chrvs[r.first][r.second];
        //printf("%d,%d:%d,%d ", n, r.first, anss[r.first], tl1[n]);
        anss[n] = anss[r.first]+tl1[n];
        rs.push(mkp(r.first, r.second+1));
        rs.push(mkp(n, 0));
    }

    fornum(i,1,N){
        printf("%d ",anss[i+1]);
    }


    return 0;
}

Measured memory_bytes: 31488