#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid (l+r>>1)
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define lowbit(x) (x&(-x))
#define inc(i, l, r) for(int i=l; i<=r; i++)
#define dec(i, r, l) for(int i=r; i>=l; i--)
const int inf = 0x3f3f3f3f;
const int maxn = 100000+10;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int mod = 1e9+7;
int readint()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll readll(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n, m;
struct Node{
int v, w, next;
}node[maxn<<1];
int tot, head[maxn];
bool vis[maxn];
int sz[maxn];
int depth[maxn];
void init(){
tot = 0;
cls(head, -1);
cls(vis, 0);
}
void add_edge(int u, int v, int w){
node[tot].v=v;
node[tot].w=w;
node[tot].next = head[u];
head[u] = tot++;
}
void dfs(int u, int fa, int dep){
vis[u] = true;
depth[u] = dep;
sz[u] = 1;
for(int i=head[u];~i; i=node[i].next){
int v=node[i].v;
if(vis[v]||v==fa) continue;
dfs(v, u, dep+1);
sz[u] += sz[v];
}
}
ll ans[maxn];
void dfs1(int u, int fa){
ans[u] = ans[fa]+n-sz[u]-sz[u];
for(int i=head[u]; ~i; i=node[i].next){
int v = node[i].v;
if(v == fa) continue;
dfs1(v, u);
}
}
void solve(){
for(int i=head[1]; ~i; i=node[i].next){
int v=node[i].v;
dfs1(v, 1);
}
}
int main()
{
while(~scanf("%d", &n)){
int u, v;
init();
inc(i, 1, n-1){
u=readint(), v=readint();
add_edge(u, v, 1), add_edge(v, u, 1);
}
dfs(1, -1, 0);
inc(i, 1, n) ans[1] += depth[i];
solve();
inc(i, 1, n) printf("%lld\n", ans[i]);
}
return 0;
}