func_code_string: #include <bits/stdc++.h>   const int INF = 200000000;   using namespace std;   int timer, lg, n;   vector<vector<int> > g;   vector<vector<int> > dp(200005);   int time_in[200005], time_out[200005], parent[200005], a[200005];   void DFS(int, int);   bool issubtree(int, int);   int lca(int, int);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     g.resize(n + 1);     lg = log2(n + 1);     for (int k = 0; k <= n; k++) dp[k].resize(lg + 1);     for (int k = 2; k <= n; k++) {       int x;       cin >> x;       a[k] = x;       g[x].push_back(k);       g[k].push_back(x);     }     int u = 1;     int v = 2;     int dist = 1;     DFS(1, 0);     cout << 1 <<    ;     for (int k = 3; k <= n; k++) {       int lca1 = lca(u, k);       int lca2 = lca(v, k);       if (lca1 > lca2) {         if (lca1 >= dist) {           v = k;           dist = lca1;         }       } else {         if (lca2 >= dist) {           u = k;           dist = lca2;         }       }       cout << dist <<    ;     }     return 0;   }   void DFS(int v, int p) {     parent[v] = p;     dp[v][0] = p;     for (int k = 1; k <= lg; k++) dp[v][k] = dp[dp[v][k - 1]][k - 1];     time_in[v] = timer++;     for (int k = 0; k < g[v].size(); k++) {       int to = g[v][k];       if (to == p) continue;       DFS(to, v);     }     time_out[v] = timer++;   }   bool issubtree(int a, int b) {     if (time_in[a] <= time_in[b] && time_out[b] <= time_out[a]) return 1;     return 0;   }   int lca(int a, int b) {     if (issubtree(a, b)) {       int cnt = 0;       for (int k = lg; k >= 0; k--) {         if (dp[b][k] == 0) continue;         if (issubtree(dp[b][k], a)) continue;         b = dp[b][k];         cnt += pow(2, k);       }       return cnt + 1;     }     if (issubtree(b, a)) {       int cnt = 0;       for (int k = lg; k >= 0; k--) {         if (dp[a][k] == 0) continue;         if (issubtree(dp[a][k], b)) continue;         a = dp[a][k];         cnt += pow(2, k);       }       return cnt + 1;     }     int cnt = 0;     int sav = a;     for (int k = lg; k >= 0; k--) {       if (dp[a][k] == 0) continue;       if (issubtree(dp[a][k], b)) continue;       a = dp[a][k];       cnt += pow(2, k);     }     a = sav;     for (int k = lg; k >= 0; k--) {       if (dp[b][k] == 0) continue;       if (issubtree(dp[b][k], a)) continue;       b = dp[b][k];       cnt += pow(2, k);     }     return cnt + 2;   }   