#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e5 + 6;
const int T = (1 << 18) + 5;
int n;
vector<int> g[N];
int par[N];
int ans[N];
int s[N], ti[N], to[N], skfjgflksd;
multiset<int> t[T];
int td;
void dfs(int v) {
  ti[v] = skfjgflksd++;
  s[v] = 1;
  for (int i : g[v]) {
    dfs(i);
    s[v] += s[i];
  }
  to[v] = skfjgflksd;
}
multiset<int> q[N];
multiset<int> up;
void ff(int v, multiset<int> &a, int mx, int mx2, int mn, int dx = 0) {
  int need = (mx - mn) / 2;
  auto it = a.lower_bound(need + dx);
  if ((mx - mn) % 2 == 0 && it != a.end() && *it == need + dx) {
    ans[v] = min(ans[v], max(mx2, max(mx - (need), mn + (need))));
    return;
  }
  if (it != a.end())
    ans[v] = min(ans[v], max(mx2, max(mx - (*it - dx), mn + (*it - dx))));
  if (it != a.begin()) {
    --it;
    ans[v] = min(ans[v], max(mx2, max(mx - (*it - dx), mn + (*it - dx))));
  }
}
void go(int v) {
  up.insert(s[v]);
  for (int i = ti[v] + td; i; i >>= 1) t[i].erase(t[i].find(s[v]));
  for (int i : g[v]) go(i);
  for (int i = ti[v] + td; i; i >>= 1) t[i].insert(s[v]);
  up.erase(up.find(s[v]));
  vector<pair<int, int>> w;
  if (par[v] != 0) w.push_back({n - s[v], -1});
  int pos = 0;
  for (int i : g[v]) w.push_back({s[i], pos++});
  sort((w).begin(), (w).end());
  reverse((w).begin(), (w).end());
  int mx = w[0].first;
  ans[v] = mx;
  if (w.size() > 1) {
    int mx2 = w[1].first, mn = w.back().first;
    if (mx2 < mx) {
      pos = w[0].second;
      if (pos != -1) {
        ff(v, q[g[v][pos]], mx, mx2, mn);
      } else {
        for (int l = 0 + td, r = ti[v] - 1 + td; l <= r; ++l >>= 1, --r >>= 1) {
          if (l & 1) ff(v, t[l], mx, mx2, mn);
          if (~r & 1) ff(v, t[r], mx, mx2, mn);
        }
        for (int l = to[v] + td, r = skfjgflksd - 1 + td; l <= r;
             ++l >>= 1, --r >>= 1) {
          if (l & 1) ff(v, t[l], mx, mx2, mn);
          if (~r & 1) ff(v, t[r], mx, mx2, mn);
        }
        ff(v, up, mx, mx2, mn, s[v]);
      }
    }
  }
  q[v].insert(s[v]);
  for (int i : g[v]) {
    multiset<int> &s1 = q[v], &s2 = q[i];
    if (s1.size() < s2.size()) s1.swap(s2);
    s1.insert((s2).begin(), (s2).end());
    s2.clear();
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int k = 1; k <= n; ++k) {
    int i, j;
    cin >> i >> j;
    g[i].push_back(j);
    par[j] = i;
  }
  dfs(g[0][0]);
  for (td = 2; td < skfjgflksd; td <<= 1)
    ;
  for (int i = 1; i <= n; ++i) t[ti[i] + td].insert(s[i]);
  for (int i = td - 1; i; --i) {
    t[i] = t[i * 2];
    t[i].insert((t[i * 2 + 1]).begin(), (t[i * 2 + 1]).end());
  }
  go(g[0][0]);
  for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
  cout << endl;
  return 0;
}
