#include <bits/stdc++.h>
using namespace std;
vector<int> edges[1000001];
int par[1000001];
int ls[1000001][25];
int llow[1000002], rlow[1000002];
int N;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &par[i]);
    par[i]--;
    edges[par[i]].push_back(i);
  }
  for (int i = N; i >= 1; i--) {
    if (edges[i].size() == 0) {
      for (int j = 0; j < 25; j++) ls[i][j] = 2000000;
      ls[i][0] = i - 1;
    } else {
      ls[i][0] = i - 1;
      llow[0] = 1000000000, rlow[edges[i].size() + 1] = 1000000000;
      for (int k = 1; k < 25; k++) {
        for (int j = 1; j <= edges[i].size(); j++)
          llow[j] = min(llow[j - 1], ls[edges[i][j - 1]][k - 1]);
        for (int j = edges[i].size(); j > 0; j--)
          rlow[j] = min(rlow[j + 1], ls[edges[i][j - 1]][k - 1]);
        ls[i][k] = 0;
        for (int j = 1; j <= edges[i].size(); j++)
          ls[i][k] = max(ls[i][k], min(min(llow[j - 1], rlow[j + 1]),
                                       ls[edges[i][j - 1]][k]));
      }
    }
  }
  ls[0][0] = 0;
  for (int k = 1; k < 25; k++) {
    ls[0][k] = 1000000000;
    for (int j = 0; j < edges[0].size(); j++)
      ls[0][k] = min(ls[0][k], ls[edges[0][j]][k]);
  }
  int k = 0;
  for (int i = 1; i <= N; i++) {
    while (ls[0][k] < i) k++;
    printf("%d ", k);
  }
  printf("\n");
  return 0;
}
