#include <bits/stdc++.h>
using namespace std;
int pa[1000010], a[1000010], b[1000010], cost[1000010];
int fa[1000010], fb[1000010];
int main() {
  int n, i, j, k, p, q;
  scanf("%d", &n);
  n++;
  for (i = 2; i <= n; i++) scanf("%d", &pa[i]);
  cost[1] = 1;
  for (i = 2; i <= n; i++) {
    p = i;
    int now, tmp;
    cost[p] = now = 1;
    while (pa[p]) {
      q = pa[p];
      int fg = 0;
      if (now > a[q]) {
        fg = 1;
        if (fa[q] != p) {
          b[q] = a[q];
          fb[q] = fa[q];
        }
        a[q] = now;
        fa[q] = p;
      } else if (p != fa[q] && now > b[q]) {
        fg = 1;
        b[q] = now;
        fb[q] = p;
      }
      tmp = (a[q] > b[q] + 1 ? a[q] : b[q] + 1);
      if (!tmp) tmp = 1;
      if (!fg) break;
      cost[q] = tmp;
      now = tmp;
      p = q;
    }
    if (a[1] != b[1])
      printf("%d", cost[1]);
    else
      printf("%d", cost[1] - 1);
    if (i < n) printf(" ");
  }
  puts("");
  return 0;
}
