#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2000000000;
const long long BIG = 1446803456761533460LL;
const int maxn = 100010;
int n, rot, res[maxn], st[maxn], ft[maxn], sz[maxn], stsz[maxn];
vector<int> subt[maxn];
multiset<int> down, up, pars;
int tim = 0;
void dfs_init(int x) {
  sz[x] = 1;
  st[x] = tim++;
  for (auto &y : subt[x]) {
    dfs_init(y);
    sz[x] += sz[y];
    if (sz[y] > sz[subt[x][0]]) swap(y, subt[x][0]);
  }
  ft[x] = tim;
}
int down_search(int mn, int mx) {
  int mid = (mn + mx + 1) / 2;
  auto it = down.lower_bound(mx - mid);
  int r = mx;
  if (it != down.end()) r = min(r, (max(mn + *it, mx - *it)));
  if (it != down.begin()) --it, r = min(r, (max(mn + *it, mx - *it)));
  return r;
}
int up_search(int mn, int mx, int sz) {
  int mid = (mn + mx + 1) / 2;
  auto it = up.lower_bound(mx - mid);
  int r = mx;
  if (it != up.end()) r = min(r, (max(mn + *it, mx - *it)));
  if (it != up.begin()) --it, r = min(r, (max(mn + *it, mx - *it)));
  it = pars.lower_bound(mx - mid + sz);
  if (it != pars.end()) r = min(r, (max(mn + (*it - sz), mx - (*it - sz))));
  if (it != pars.begin())
    --it, r = min(r, (max(mn + (*it - sz), mx - (*it - sz))));
  return r;
}
void dfs_calc(int x) {
  up.erase(up.find(sz[x]));
  if (subt[x].empty()) {
    res[x] = n - 1;
    down.insert(sz[x]);
    return;
  }
  pars.insert(sz[x]);
  int mn = sz[subt[x][0]];
  if (sz[x] != n) mn = min(mn, (n - sz[x]));
  for (int yi = 1; yi < (int)subt[x].size(); ++yi) {
    int y = subt[x][yi];
    mn = min(mn, (sz[y]));
    dfs_calc(y);
    for (int i = st[y]; i < ft[y]; ++i) {
      down.erase(down.find(stsz[i]));
      up.insert(stsz[i]);
    }
  }
  dfs_calc(subt[x][0]);
  for (int yi = 1; yi < (int)subt[x].size(); ++yi) {
    int y = subt[x][yi];
    for (int i = st[y]; i < ft[y]; ++i) {
      up.erase(up.find(stsz[i]));
    }
  }
  if (sz[subt[x][0]] > n - sz[x]) {
    res[x] = down_search(mn, sz[subt[x][0]]);
    res[x] = max(res[x], (n - sz[x]));
  } else {
    res[x] = up_search(mn, n - sz[x], sz[x]);
    res[x] = max(res[x], (sz[subt[x][0]]));
  }
  for (int yi = 1; yi < (int)subt[x].size(); ++yi)
    res[x] = max(res[x], (sz[subt[x][yi]]));
  for (int yi = 1; yi < (int)subt[x].size(); ++yi) {
    int y = subt[x][yi];
    for (int i = st[y]; i < ft[y]; ++i) {
      down.insert(stsz[i]);
    }
  }
  down.insert(sz[x]);
  pars.erase(pars.find(sz[x]));
}
void solve() {
  dfs_init(rot);
  for (int i = 0; i < n; ++i) stsz[st[i]] = sz[i], up.insert(sz[i]);
  dfs_calc(rot);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    if (u == -1)
      rot = v;
    else
      subt[u].emplace_back(v);
  }
  solve();
  for (int i = 0; i < n; ++i) cout << res[i] << '\n';
}
