#include <bits/stdc++.h>   using namespace std;   const int N = 233333;   int par[N][25], dep[N];   int u, v, ans;   int n;   inline int lca(int u, int v) {     if (dep[u] < dep[v]) {       u ^= v;       v ^= u;       u ^= v;     }     for (int i = 0; i < 25; i++)       if (((dep[u] - dep[v]) >> i) & 1) u = par[u][i];     if (u == v) return u;     for (int i = 24; i >= 0; i--)       if (par[u][i] != par[v][i]) {         u = par[u][i];         v = par[v][i];       }     return par[u][0];   }   int main() {     scanf( %d , &n);     par[1][0] = 0;     dep[1] = 0;     u = v = 1;     for (int i = 2; i <= n; i++) {       int w;       scanf( %d , &w);       par[i][0] = w;       dep[i] = dep[w] + 1;       for (int j = 1; j < 24; j++) par[i][j] = par[par[i][j - 1]][j - 1];       w = i;       int l = lca(u, w);       int dst = dep[u] - dep[l] + dep[w] - dep[l];       int nu = u, nv = v;       if (dst > ans) {         ans = dst;         nu = u;         nv = w;       }       l = lca(v, w);       dst = dep[v] - dep[l] + dep[w] - dep[l];       if (dst > ans) {         ans = dst;         nu = w;         nv = v;       }       printf( %d%c , ans, i == n ?   n  :    );       u = nu;       v = nv;     }     return 0;   }   