#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
const int MAXN = 70000;
int n;
vector<int> adj[MAXN];
int ans[MAXN];
bool alive[MAXN];
int sz[MAXN], dep[MAXN];
int mindst[MAXN];
int q[MAXN], qhead, qtail;
void dfsinit(int at, int par) {
sz[at] = 1, dep[at] = (par == -1 ? 0 : dep[par] + 1);
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || !alive[to]) continue;
dfsinit(to, at);
sz[at] += sz[to];
}
}
int centroid(int root) {
dfsinit(root, -1); int at = root, par = -1;
while (true) {
bool change = false;
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || !alive[to]) continue;
if (2 * sz[to] > sz[root]) { change = true; par = at; at = to; break; }
}
if (!change) return at;
}
}
int cost[MAXN];
void modcost(int at, int par, int lim, int by) {
int nlim = max(0, min(lim, mindst[at] - dep[at]));
FOR(x, nlim, lim) cost[x] += by;
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || !alive[to]) continue;
modcost(to, at, nlim, by);
}
}
void inccost(int at, int lim) {
if (dep[at] < lim) ans[at] += cost[dep[at]];
}
void addcost(int at, int par, int lim) {
int nlim = min(lim, dep[at] + mindst[at]);
inccost(at, nlim);
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || !alive[to]) continue;
addcost(to, at, nlim);
}
}
void process(int at) {
// Find centroid and initialize tree
at = centroid(at);
dfsinit(at, -1);
// Add costs
FOR(x, mindst[at], sz[at]) ++cost[x];
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (!alive[to]) continue;
modcost(to, at, mindst[at], +1);
}
// Process paths through centroid
inccost(at, INT_MAX);
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (!alive[to]) continue;
modcost(to, at, mindst[at], -1);
addcost(to, at, INT_MAX);
modcost(to, at, mindst[at], +1);
}
// Remove costs
FOR(x, mindst[at], sz[at]) --cost[x];
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (!alive[to]) continue;
modcost(to, at, mindst[at], -1);
}
// Process paths not going through centroid
alive[at] = false;
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (!alive[to]) continue;
process(to);
}
}
void run() {
scanf("%d", &n); REP(i, n - 1) { int a, b; scanf("%d%d", &a, &b); --a, --b; adj[a].PB(b); adj[b].PB(a); }
REP(i, n) mindst[i] = INT_MAX; qhead = qtail = 0;
REP(i, n) if (SZ(adj[i]) <= 1) mindst[i] = 0, q[qhead++] = i;
while (qtail < qhead) {
int at = q[qtail++];
REPSZ(i, adj[at]){
int to = adj[at][i]; if (mindst[to] != INT_MAX) continue;
mindst[to] = mindst[at] + 1; q[qhead++] = to;
}
}
REP(i, n) alive[i] = true, ans[i] = 0; memset(cost, 0, sizeof(cost));
process(0);
REP(i, n) printf("%d\n", ans[i]);
}
int main() {
freopen("atlarge.in", "r", stdin);
freopen("atlarge.out", "w", stdout);
run();
return 0;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4gIAojaW5jbHVkZSA8aW9zdHJlYW0+ICAKI2luY2x1ZGUgPHNzdHJlYW0+ICAKI2luY2x1ZGUgPHN0cmluZz4gIAojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4gIAojaW5jbHVkZSA8cXVldWU+ICAKI2luY2x1ZGUgPHNldD4gIAojaW5jbHVk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