#include <bits/stdc++.h>
using namespace std;
struct LCA {
  vector<vector<int> > g;
  const int MAX_LOG = 22;
  vector<vector<int> > lcc;
  vector<int> dep;
  vector<int> myr;

 private:
  void init2() {
    int n = g.size();
    for (int i = 0; i + 1 < MAX_LOG; i++) {
      for (int j = 0; j < n; j++) {
        if (lcc[i][j] == -1) {
          lcc[i + 1][j] = -1;
          continue;
        }
        lcc[i + 1][j] = lcc[i][lcc[i][j]];
      }
    }
  }

 public:
  int lca(int a, int b) {
    if (myr[a] != myr[b]) {
      return -1;
    }
    if (dep[a] < dep[b]) {
      swap(a, b);
    }
    for (int i = 0; i < MAX_LOG; i++) {
      if (((dep[a] - dep[b]) >> i) & 1) {
        a = lcc[i][a];
      }
    }
    if (a == b) {
      return a;
    }
    for (int i = MAX_LOG - 1; i >= 0; i--) {
      if (lcc[i][a] != lcc[i][b]) {
        a = lcc[i][a];
        b = lcc[i][b];
      }
    }
    return lcc[0][a];
  }

 private:
  int flag_r;
  inline void dfs(int b, int pr = -1, int d = 0) {
    for (auto &i : g[b]) {
      if (i == pr) continue;
      dfs(i, b, d + 1);
    }
    dep[b] = d;
    lcc[0][b] = pr;
    myr[b] = flag_r;
  }

 public:
  void init(vector<vector<int> > &tree, int root = 0) {
    g = tree;
    myr.resize(tree.size(), -1);
    flag_r = root;
    lcc.resize(MAX_LOG, vector<int>(g.size(), 0));
    dep.resize(g.size());
    dfs(root);
    init2();
  }
  void init(vector<vector<int> > &tree, vector<int> &root) {
    g = tree;
    myr.resize(tree.size(), -1);
    lcc.resize(MAX_LOG, vector<int>(g.size(), 0));
    dep.resize(g.size());
    for (int &i : root) {
      if (myr[i] == -1) {
        flag_r = i;
        dfs(i);
      }
    }
    init2();
  }
  int dist(int a, int b) {
    if (myr[a] != myr[b]) {
      return -1;
    }
    int lc = lca(a, b);
    return dep[a] + dep[b] - 2 * dep[lc];
  }
  int go(int a, int b) {
    for (int i = 0; i < MAX_LOG; i++) {
      if ((b >> i) & 1) {
        a = lcc[i][a];
      }
    }
    return a;
  }
};
vector<vector<int> > v;
int m;
LCA lc;
pair<int, int> dia[300002];
int ds[300002];
int im[300002];
bool ok(int node, int id) {
  return max(lc.dist(node, dia[id].first), lc.dist(node, dia[id].second)) ==
         ds[id];
}
int main() {
  cin >> m;
  v.assign(m + 1, vector<int>());
  for (int i = 1; i <= m; i++) {
    int y;
    scanf("%d", &y);
    y--;
    v[y].push_back(i);
  }
  lc.init(v, 0);
  int dist = 0;
  dia[1] = make_pair(0, 1);
  ds[1] = 1;
  for (int i = 2; i <= m; i++) {
    dia[i] = dia[i - 1];
    int nex = lc.dist(dia[i - 1].first, i);
    if (dist <= nex) {
      dia[i] = dia[i - 1];
      dist = nex;
      dia[i].second = i;
    }
    nex = lc.dist(dia[i - 1].second, i);
    if (dist <= nex) {
      dia[i] = dia[i - 1];
      dist = nex;
      dia[i].first = i;
    }
    ds[i] = dist;
  }
  for (int i = 0; i <= m; i++) {
    if (i == 0 || dia[i].first == i || dia[i].second == i) {
      im[i]++;
    } else {
      continue;
    }
    int mint = i;
    int maxt = m;
    while (mint + 1 < maxt) {
      int mid = (mint + maxt) >> 1;
      if (ok(i, mid)) {
        mint = mid;
      } else {
        maxt = mid - 1;
      }
    }
    if (ok(i, maxt)) {
      mint = maxt;
    } else {
      maxt = mint;
    }
    im[mint + 1]--;
  }
  for (int i = 1; i <= m; i++) {
    im[i] += im[i - 1];
    printf("%d\n", im[i]);
  }
  return 0;
}
