#include <bits/stdc++.h>
using namespace std;
multiset<int> S[1100000];
int pd[1100000];
vector<int> E[1100000];
int pai[1100000];
int n;
int calc(int v) {
  if (S[v].size() == 0) return 1;
  if (S[v].size() == 1)
    return -(*(S[v].begin()));
  else {
    multiset<int>::iterator it = S[v].begin();
    if (v == 0) return -(*it);
    int y = -(*it);
    it++;
    return max(y, -(*it) + 1);
  }
}
void solve(int v, int p) {
  pai[v] = p;
  for (int i = 0; i < E[v].size(); i++) {
    int viz = E[v][i];
    if (viz == p) continue;
    solve(viz, v);
    S[v].insert(-pd[viz]);
  }
  pd[v] = calc(v);
}
void update(int v) {
  int ret = calc(v);
  if (ret == pd[v]) return;
  int ant = pd[v];
  pd[v] = ret;
  if (pai[v] == -1) return;
  S[pai[v]].erase(S[pai[v]].find(-ant));
  S[pai[v]].insert(-pd[v]);
  update(pai[v]);
}
int main() {
  cin >> n;
  n++;
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    E[a - 1].push_back(i + 1);
  }
  solve(0, -1);
  vector<int> ans;
  for (int i = n - 1; i > 0; i--) {
    ans.push_back(pd[0]);
    S[pai[i]].erase(S[pai[i]].find(-1));
    update(pai[i]);
  }
  reverse((ans).begin(), (ans).end());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  return 0;
}
