#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, q, k;
const int N = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 61LL;
long long arr[N];
vector<int> adj[N];
long long sz[N];
string str, ss;
map<int, long long> I, O;
map<int, long long> path;
int root;
long long sol[N];
void build(int v) {
  sz[v] = 1;
  for (int u : adj[v]) {
    build(u);
    sz[v] += sz[u];
  }
  O[sz[v]]++;
}
void remove(map<int, long long>& M, int val) {
  auto it = M.find(val);
  if (it != M.end()) it->second--;
  if (it->second == 0) M.erase(it);
}
bool heaviest[N];
void insert(int v) {
  remove(O, sz[v]);
  I[sz[v]]++;
  for (int u : adj[v]) {
    insert(u);
  }
}
void rem(int v) {
  remove(I, sz[v]);
  O[sz[v]]++;
  for (int u : adj[v]) {
    rem(u);
  }
}
int get(map<int, long long>& toFind, int s, int e, int mi, int offset) {
  int lo = s;
  int hi = e;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    auto it = toFind.lower_bound(e - mid + offset);
    if (it == toFind.end()) {
      lo = mid + 1;
    } else if (mi + it->first <= mid + offset)
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}
void solve(int v, int p, bool heavy) {
  int mx = 0, smx = 0, mn = -1;
  remove(O, sz[v]);
  path[sz[v]]++;
  if (adj[v].size() == 0) {
    sol[v] = n - sz[v];
    remove(path, sz[v]);
    if (!heavy) {
      O[sz[v]]++;
      for (int u : adj[v]) {
        rem(u);
      }
    } else
      I[sz[v]]++;
    return;
  }
  for (int i = 0; i < adj[v].size(); ++i) {
    int u = adj[v][i];
    if (sz[u] > sz[mx]) {
      smx = mx;
      mx = u;
    } else if (sz[u] > sz[smx]) {
      smx = u;
    }
    if (mn == -1 || sz[u] < sz[mn]) mn = u;
  }
  for (int u : adj[v]) {
    if (u == mx) continue;
    solve(u, v, false);
  }
  solve(mx, v, true);
  if (n - sz[v] <= sz[mx]) {
    if (v != root)
      sol[v] =
          get(I, max(n - sz[v], sz[smx]), sz[mx], min(n - sz[v], sz[mn]), 0);
    else
      sol[v] = get(I, max(n - sz[v], sz[smx]), sz[mx], sz[mn], 0);
  }
  for (int u : adj[v]) {
    if (u == mx) continue;
    insert(u);
  }
  if (n - sz[v] > sz[mx]) {
    sol[v] = min(get(path, sz[mx], n - sz[v], sz[mn], sz[v]),
                 get(O, sz[mx], n - sz[v], sz[mn], 0));
  }
  remove(path, sz[v]);
  if (!heavy) {
    O[sz[v]]++;
    for (int u : adj[v]) {
      rem(u);
    }
  } else
    I[sz[v]]++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    if (u == 0) root = v;
  }
  build(root);
  solve(root, 0, 0);
  for (int i = 1; i <= n; ++i) {
    cout << sol[i] << '\n';
  }
  return 0;
}
