#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
vector<int> mp[100005];
int sz[100005], bigSon[100005], st[100005], ed[100005], cnt, rid[100005];
multiset<int> mpc, mpp, mpo;
int mic[100005];
void dfs(int x) {
  sz[x] = 1;
  st[x] = ++cnt;
  rid[cnt] = x;
  int mx = 0;
  mic[x] = (1 << 30);
  for (int c : mp[x]) {
    dfs(c);
    sz[x] += sz[c];
    mic[x] = min(mic[x], sz[c]);
    if (mx < sz[c]) {
      mx = sz[c];
      bigSon[x] = c;
    }
  }
  if (x != mp[0][0]) mic[x] = min(mic[x], n - sz[x]);
  ed[x] = cnt;
}
int ans[100005];
void dfs1(int x, bool fg) {
  int sb = 0;
  mpp.insert(sz[x]);
  mpo.erase(mpo.find(sz[x]));
  for (int c : mp[x])
    if (c != bigSon[x]) {
      sb = max(sb, sz[c]);
      dfs1(c, 0);
    }
  if (bigSon[x] != 0) dfs1(bigSon[x], 1);
  mpp.erase(mpp.find(sz[x]));
  if (x == 1) {
    int gh = 0;
  }
  if (n - sz[x] < sz[bigSon[x]]) {
    int tar = (sz[bigSon[x]] + mic[x] + 1) / 2;
    auto it = mpc.upper_bound(sz[bigSon[x]] - tar);
    ans[x] = sz[bigSon[x]];
    if (it != mpc.end()) {
      ans[x] = min(ans[x], max(max(sb, n - sz[x]),
                               max(sz[bigSon[x]] - (*it), mic[x] + (*it))));
    }
    if (it != mpc.begin()) {
      it--;
      ans[x] = min(ans[x], max(max(sb, n - sz[x]),
                               max(sz[bigSon[x]] - (*it), mic[x] + (*it))));
    }
  } else {
  }
  for (int c : mp[x])
    if (c != bigSon[x]) {
      for (int i = st[c]; i <= ed[c]; i++) {
        int v = rid[i];
        mpc.insert(sz[v]);
        mpo.erase(mpo.find(sz[v]));
      }
    }
  if (n - sz[x] > sz[bigSon[x]]) {
    int S = n - sz[x];
    int tar = (S + mic[x] + 1) / 2;
    auto it = mpo.upper_bound(S - tar);
    ans[x] = S;
    if (it != mpo.end()) {
      ans[x] = min(ans[x],
                   max(max(sb, sz[bigSon[x]]), max(S - (*it), mic[x] + (*it))));
    }
    if (it != mpo.begin()) {
      it--;
      ans[x] = min(ans[x],
                   max(max(sb, sz[bigSon[x]]), max(S - (*it), mic[x] + (*it))));
    }
    it = mpp.upper_bound(S - tar + sz[x]);
    if (it != mpp.end()) {
      ans[x] = min(ans[x], max(max(sb, sz[bigSon[x]]),
                               max(S - (*it) + sz[x], mic[x] + (*it) - sz[x])));
    }
    if (it != mpp.begin()) {
      it--;
      ans[x] = min(ans[x], max(max(sb, sz[bigSon[x]]),
                               max(S - (*it) + sz[x], mic[x] + (*it) - sz[x])));
    }
  } else if (n - sz[x] == sz[bigSon[x]])
    ans[x] = sz[bigSon[x]];
  mpc.insert(sz[x]);
  if (fg == 0) {
    for (int i = st[x]; i <= ed[x]; i++) {
      int v = rid[i];
      mpo.insert(sz[v]);
      mpc.erase(mpc.find(sz[v]));
    }
  }
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int u, v;
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
  }
  dfs(mp[0][0]);
  for (int(i) = 1; (i) <= (int)(n); (i)++) mpo.insert(sz[i]);
  dfs1(mp[0][0], 0);
  for (int(i) = 1; (i) <= (int)(n); (i)++) printf("%d\n", ans[i]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
