#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 11;
typedef int i_N[maxN];
int N;
vector<int> adj[maxN];
i_N P, T;
void dfs(int u, list<int> *&que, pair<int, int> &ans) {
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (P[v]) continue;
    pair<int, int> res;
    list<int> *tmp = new list<int>();
    P[v] = u;
    dfs(v, tmp, res);
    if (que->empty()) {
      que = tmp;
      ans = res;
    } else {
      if (que->size() < tmp->size()) {
        swap(que, tmp);
        swap(ans, res);
      }
      int C = 0;
      for (list<int>::iterator it1 = tmp->begin(), it2 = que->begin();
           it1 != tmp->end(); it1++, it2++, C++) {
        *it2 += *it1;
        if (*it2 > ans.second || (*it2 == ans.second && C < ans.first))
          ans = pair<int, int>(C, *it2);
      }
      tmp->clear();
      delete tmp;
    }
  }
  if (que->empty() || ans.second == 1)
    ans = pair<int, int>(0, 1);
  else
    ans.first++;
  que->push_front(1);
  T[u] = ans.first;
}
int main() {
  scanf("%d\n", &N);
  for (int i = 1; i <= N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  pair<int, int> ans;
  list<int> *tmp = new list<int>();
  P[1] = -1;
  dfs(1, tmp, ans);
  for (int u = 1; u <= N; u++) printf("%d\n", T[u]);
}
