#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];
int sz[MAXN], heavy[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), heavy[at] = -1;
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par) continue;
dfsinit(to, at);
sz[at] += sz[to]; if (heavy[at] == -1 || sz[to] > sz[heavy[at]]) heavy[at] = to;
}
}
int acost[MAXN];
void modacost(int at, int par, int deplca, int lim, int by) {
int nlim = max(deplca, min(lim, mindst[at] + 2 * deplca - dep[at]));
FOR(x, nlim, lim) acost[x] += by;
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par) continue;
modacost(to, at, deplca, nlim, by);
}
}
int bcost[2 * MAXN + 1], blim;
void modbcost(int at, int par, int lim, int by) {
int nlim = mindst[at] - dep[at];
FOR(x, nlim, lim) bcost[x + MAXN] += by;
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par) continue;
modbcost(to, at, nlim, by);
}
}
void incbcost(int at, int deplca) {
ans[at] += dep[at] - 2 * deplca >= blim ? 0 : bcost[dep[at] - 2 * deplca + MAXN]; // >=blim already included in acost
}
void addbcost(int at, int par,int deplca) {
incbcost(at, deplca);
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par) continue;
addbcost(to, at, deplca);
}
}
// Before acost contains all light siblings of ancestors and bcost is empty. Afterwards acost is unchanged and bcost contains the entire subtree.
void process(int at, int par, int alim) {
int nalim = dep[at] + mindst[at]; assert(nalim >= alim); FOR(x, alim, nalim) acost[x] = 1; alim = nalim;
// for each light subtree: add it to acost
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || to == heavy[at]) continue;
modacost(to, at, dep[at], alim, +1);
}
// for each light subtree: remove it from acost, process it, re-add it to acost and remove it from bcost
ans[at] += dep[at] >= alim ? 1 : acost[dep[at]];
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || to == heavy[at]) continue;
modacost(to, at, dep[at], alim, -1);
process(to, at, alim);
modbcost(to, at, blim, -1);
modacost(to, at, dep[at], alim, +1);
}
// process heavy subtree
int nblim = mindst[at] - dep[at];
if (heavy[at] != -1) {
process(heavy[at], at, alim);
assert(nblim >= blim); FOR(x, blim, nblim) bcost[x + MAXN] = 1; blim = nblim;
} else {
blim = nblim;
}
// for each light subtree: update answer with bcost
incbcost(at, dep[at]);
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || to == heavy[at]) continue;
addbcost(to, at, dep[at]);
}
// for each light subtree: remove it from acost and re-add it to bcost
REPSZ(i, adj[at]) {
int to = adj[at][i]; if (to == par || to == heavy[at]) continue;
modacost(to, at, dep[at], alim, -1);
modbcost(to, at, blim, +1);
}
}
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) ans[i] = 0; memset(acost, 0, sizeof(acost)); memset(bcost, 0, sizeof(bcost));
dfsinit(0, -1);
process(0, -1, dep[0] + mindst[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+ICAKI2luY2x1ZGUgPHNldD4gIAojaW5jbHVkZSA8bWFwPiAgCiNpbmNsdWRlIDxjc3RkaW8+ICAKI2luY2x1ZGUgPGNzdGRsaWI+ICAKI2luY2x1ZGUgPGNjdHlwZT4gIAojaW5jbHVkZSA8Y21hdGg+ICAKI2luY2x1ZGUgPGxpc3Q+ICAKI2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPGNsaW1pdHM+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIFBCIHB1c2hfYmFjayAgCiNkZWZpbmUgTVAgbWFrZV9wYWlyICAKI2RlZmluZSBTWih2KSAoKGludCkodikuc2l6ZSgpKSAgCiNkZWZpbmUgRk9SKGksYSxiKSBmb3IoaW50IGk9KGEpO2k8KGIpOysraSkgIAojZGVmaW5lIFJFUChpLG4pIEZPUihpLDAsbikgIAojZGVmaW5lIEZPUkUoaSxhLGIpIGZvcihpbnQgaT0oYSk7aTw9KGIpOysraSkgIAojZGVmaW5lIFJFUEUoaSxuKSBGT1JFKGksMCxuKSAgCiNkZWZpbmUgRk9SU1ooaSxhLHYpIEZPUihpLGEsU1oodikpICAKI2RlZmluZSBSRVBTWihpLHYpIFJFUChpLFN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