#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template <typename T>
using vt = std::vector<T>;
using vi = vt<int>;
using vvi = vt<vi>;
using vvvi = vt<vvi>;
using vl = vt<ll>;
using vvl = vt<vl>;
using vvvl = vt<vvl>;
using vb = vt<bool>;
using vpii = vt<pii>;
static inline void Solve();
int main(int argc, char* argv[]) {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  Solve();
  return 0;
}
tuple<int, int, vi> dfs(vi& ans, const vvi& edges, int cur, int prt) {
  int mi = 0, m = 1;
  vi l{};
  for (auto e : edges[cur]) {
    if (e == prt) continue;
    int ni, nm;
    vi nl;
    std::tie(ni, nm, nl) = dfs(ans, edges, e, cur);
    if (make_pair(nm, -ni - 1) > make_pair(m, -mi)) {
      mi = ni + 1, m = nm;
    }
    if (nl.size() > l.size()) {
      l.swap(nl);
    }
    for (int i = 1; i <= (int)nl.size(); i++) {
      l[l.size() - i] += nl[nl.size() - i];
      if (make_pair(l[l.size() - i], -i) > make_pair(m, -mi)) {
        mi = i, m = l[l.size() - i];
      }
    }
  }
  l.push_back(1);
  ans[cur] = mi;
  return make_tuple(mi, m, std::move(l));
}
void Solve() {
  int n;
  cin >> n;
  vvi edges(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  vi ans(n);
  dfs(ans, edges, 0, -1);
  for (auto a : ans) {
    cout << a << '\n';
  }
  cout << flush;
}
