#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline int getint() {
  int x;
  char c = nc(), b = 1;
  if (c == -1) return 0;
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
  return x;
}
int n;
vector<int> g[1000010];
int ans[1000010];
int calc(int up) {
  for (int i = up; i >= 1; i--) {
    int mx = 0, se = 0;
    for (int v : g[i]) {
      if (v > up) break;
      if (se < ans[v]) se = ans[v];
      if (mx < se) swap(mx, se);
    }
    ans[i] = max(mx, se + (i > 1));
  }
  return ans[1];
}
int rlt[1000010];
void solve(int l, int vl, int r, int vr) {
  if (vl == vr) {
    for (int i = l; i <= r; i++) rlt[i] = vl;
    return;
  }
  if (r - l == 1) {
    rlt[l] = vl, rlt[r] = vr;
    return;
  }
  int m = l + r >> 1;
  int vm = calc(m);
  solve(l, vl, m, vm);
  solve(m, vm, r, vr);
}
int main() {
  n = getint();
  n++;
  for (int i = 2; i <= n; i++) {
    int x;
    x = getint();
    g[x].push_back(i);
  }
  int now = calc(n);
  assert(now <= 50);
  solve(1, 0, n, now);
  for (int i = 2; i <= n; i++) printf("%d ", rlt[i]);
  return 0;
}
