#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 0;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f ? x : -x;
}
const int maxn = 1e5 + 10, maxm = maxn << 1;
int rt;
int sz[maxn], f[maxn], head[maxn], son[maxn], to[maxm], nxt[maxm], ans[maxn], n,
    e;
multiset<int> mp[maxn], anc, Ote;
void add(int x, int y) {
  to[++e] = y;
  nxt[e] = head[x];
  head[x] = e;
}
void dfs(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    dfs(v);
    sz[u] += sz[v];
    if (!son[u] || sz[son[u]] < sz[v]) son[u] = v;
  }
  if (u != rt) Ote.insert(sz[u]);
}
int ck(int u, int mid, int fg, int Max, int Min) {
  if (fg) {
    multiset<int>::iterator it = mp[son[u]].lower_bound(Max - mid);
    if (it != mp[son[u]].end() && *it >= Max - mid && *it <= mid - Min)
      return 1;
  } else {
    multiset<int>::iterator it = Ote.lower_bound(Max - mid);
    if (it != Ote.end() && *it >= Max - mid && *it <= mid - Min) return 1;
    it = anc.lower_bound(Max - mid + sz[u]);
    if (it != anc.end() && *it - sz[u] >= Max - mid && *it - sz[u] <= mid - Min)
      return 1;
  }
  return 0;
}
void gao(int u) {
  if (u != rt) Ote.erase(Ote.lower_bound(sz[u]));
  if (f[u] != rt && f[u] != 0) anc.insert(sz[f[u]]);
  int Min = n - sz[u];
  if (Min == 0) Min = 0x3f3f3f3f;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == son[u]) continue;
    gao(v);
    for (multiset<int>::iterator it = mp[v].begin(); it != mp[v].end(); ++it)
      Ote.insert(*it);
    Min = min(sz[v], Min);
  }
  if (son[u]) gao(son[u]), Min = min(sz[son[u]], Min);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v != son[u])
      for (multiset<int>::iterator it = mp[v].begin(); it != mp[v].end(); ++it)
        Ote.erase(Ote.lower_bound(*it));
  }
  int Max = max(n - sz[u], sz[son[u]]);
  int Max1 = min(n - sz[u], sz[son[u]]);
  int tmp = (Max == sz[son[u]] && son[u]) ? 1 : 0;
  int fg = 0;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != son[u]) Max1 = max(Max1, sz[to[i]]);
  if (Max1 == Max) fg = 1;
  int l = Max1, r = Max;
  if (!fg)
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (ck(u, mid, tmp, Max, Min))
        ans[u] = mid, r = mid - 1;
      else
        l = mid + 1;
    }
  if (!ans[u]) ans[u] = Max;
  if (son[u]) swap(mp[u], mp[son[u]]);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == son[u]) continue;
    for (multiset<int>::iterator it = mp[v].begin(); it != mp[v].end();
         mp[v].erase(it++))
      mp[u].insert(*it);
  }
  if (f[u] != rt && f[u] != 0) anc.erase(anc.lower_bound(sz[f[u]]));
  mp[u].insert(sz[u]);
}
int main() {
  n = read();
  rt = 0;
  for (int i = 2; i <= n + 1; ++i) {
    int x = read(), y = read();
    f[y] = x;
    if (!x)
      rt = y;
    else
      add(x, y);
  }
  dfs(rt);
  gao(rt);
  for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
  return 0;
}
