#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do x = x * 10 + (c ^ 48);
  while (c = getchar(), c > 47);
}
template <class T>
void rec_pt(T x) {
  if (!x) return;
  rec_pt(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T>
void pt(T x) {
  if (!x)
    putchar('0');
  else
    rec_pt(x);
}
template <class T>
inline void ptn(T x) {
  pt(x), putchar('\n');
}
template <class T>
inline void Max(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void Min(T &a, T b) {
  if (b < a) a = b;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = (int)1e6 + 5;
int tot_edge, head[N], par[N], dep[N], mx_dep[N], son[N], top[N];
pair<int, int> edge[N << 1];
int ans[N], memo[N << 2], *allc = memo, *f[N];
void add_edge(int u, int v) {
  edge[tot_edge] = pair<int, int>(v, head[u]);
  head[u] = tot_edge++;
}
void dfs(int u) {
  for (int i = head[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u]) continue;
    par[v] = u;
    dep[v] = dep[u] + 1;
    dfs(v);
    if (!son[u] || mx_dep[v] > mx_dep[son[u]]) son[u] = v;
  }
  if (son[u]) mx_dep[u] = mx_dep[son[u]] + 1;
}
void allc_dfs(int u, int anc) {
  top[u] = anc;
  if (son[u])
    allc_dfs(son[u], anc);
  else {
    int sz = dep[u] - dep[top[u]] + 1;
    f[u] = allc += sz;
    allc += sz << 1;
    return;
  }
  for (int i = head[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u] || v == son[u]) continue;
    allc_dfs(v, v);
  }
}
void DP(int u) {
  if (!son[u]) {
    f[u][0] = 1;
    return;
  }
  for (int i = head[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u]) continue;
    DP(v);
  }
  f[u] = f[son[u]] - 1;
  f[u][0] = 1;
  if (f[son[u]][ans[son[u]]] > 1) ans[u] = ans[son[u]] + 1;
  for (int i = head[u]; ~i; i = edge[i].second) {
    int v = edge[i].first;
    if (v == par[u] || v == son[u]) continue;
    for (int j = (1), _t = (mx_dep[v] + 2); j < _t; ++j) {
      f[u][j] += f[v][j - 1];
      if (f[u][j] > f[u][ans[u]])
        ans[u] = j;
      else if (f[u][j] == f[u][ans[u]])
        Min(ans[u], j);
    }
  }
}
int main() {
  int n;
  rd(n);
  memset(head, -1, n + 1 << 2);
  for (int i = 1, u, v; i < n; ++i) {
    rd(u), rd(v);
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1);
  allc_dfs(1, 1);
  DP(1);
  for (int i = (1), _t = (n + 1); i < _t; ++i) ptn(ans[i]);
  return 0;
}
