#include <bits/stdc++.h>
using namespace std;
const long long int INF = 9223372036854775807;
const long long int mod = 1000000007;
int MOD(int a, int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
long long int max3(long long int a, long long int b, long long int c) {
  return max(c, max(a, b));
}
long long int min3(long long int a, long long int b, long long int c) {
  return min(a, min(b, c));
}
long long int power(long long int x, long long int y, long long int mod1) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod1;
    y = y >> 1;
    x = (x * x) % mod1;
  }
  return res;
}
long long int logg(long long int a) {
  long long int x = 0;
  while (a > 1) {
    x++;
    a /= 2;
  }
  return x;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int abso(long long int x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
long long int ceiling(long long int a, long long int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long int modinv(long long int x, long long int p) {
  return power(x, p - 2, p);
}
int n;
vector<vector<int> > adj;
vector<int> vis;
vector<int> d;
vector<int> ans;
vector<vector<int>*> g;
pair<int, int> solve(int i) {
  vis[i] = 1;
  pair<int, int> ans1 = make_pair(-1, -1);
  d[i] = 1;
  for (int j = 0; j < adj[i].size(); j++) {
    if (!vis[adj[i][j]]) {
      auto cur = solve(adj[i][j]);
      ans1 = max(ans1, cur);
      d[i] = max(d[adj[i][j]] + 1, d[i]);
      if (j == 0) {
        g[i] = g[adj[i][j]];
        continue;
      }
      if (((*(g[adj[i][j]])).size()) > (*(g[i])).size()) {
        int kk = (int)(*(g[adj[i][j]])).size() - 1;
        for (int k = (int)(*(g[i])).size() - 1; k >= 0; k--) {
          (*g[adj[i][j]])[kk] += (*g[i])[k];
          ans1 = max(ans1, make_pair((*(g[adj[i][j]]))[kk], kk));
          kk--;
        }
        g[i] = g[adj[i][j]];
      } else {
        int kk = (int)(*(g[i])).size() - 1;
        for (int k = (int)(*(g[adj[i][j]])).size() - 1; k >= 0; k--) {
          (*g[i])[kk] += (*g[adj[i][j]])[k];
          ans1 = max(ans1, make_pair((*(g[i]))[kk], kk));
          kk--;
        }
      }
    }
  }
  (*g[i]).push_back(1);
  ans1 = max(ans1, make_pair(1, (int)(*(g[i])).size() - 1));
  ans[i] = ans1.second;
  return ans1;
}
int main() {
  scanf("%d", &n);
  adj.resize(n + 1);
  vis.resize(n + 1);
  d.resize(n + 1);
  ans.resize(n + 1);
  g.resize(n + 1);
  for (int i = 0; i <= n; i++) {
    g[i] = new vector<int>;
  }
  for (int j = 1; j <= n - 1; j++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  solve(1);
  for (int i = 1; i <= n; i++) {
    printf("%d\n", (int)d[i] - ans[i] - 1);
  }
}
