func_code_string: #include <bits/stdc++.h>   using namespace std;   constexpr int N = 1e6 + 10;   constexpr int M = 30;   long long a1 = 2, a2 = 4, n, ans = 2, t = 4, dis[N], dp[N][M], v, dist1, dist2;   int get_lca(int a, int b) {     if (dis[a] < dis[b]) swap(a, b);     while (dis[a] != dis[b]) a = dp[a][(int)log2(dis[a] - dis[b])];     for (int i = M - 1; i >= 0; i--) {       if (a == b)         return a;       else if (dp[a][i] != dp[b][i]) {         a = dp[a][i];         b = dp[b][i];         return get_lca(a, b);       }     }     return dp[a][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     dp[2][0] = 1;     dp[3][0] = 1;     dp[4][0] = 1;     dis[2] = dis[3] = dis[4] = 1;     for (int i = 0; i < n; i++) {       cin >> v;       dp[++t][0] = v;       dp[++t][0] = v;       dis[t - 1] = dis[v] + 1;       dis[t] = dis[v] + 1;       for (int j = 1; j < M; j++) {         dp[t - 1][j] = dp[dp[t - 1][j - 1]][j - 1];         dp[t][j] = dp[dp[t][j - 1]][j - 1];       }       dist1 = dis[t] + dis[a1] - 2 * dis[get_lca(t, a1)];       dist2 = dis[t] + dis[a2] - 2 * dis[get_lca(t, a2)];       if (dist1 >= dist2 && dist1 > ans) {         ans = dist1;         a2 = t;       } else if (dist2 > dist1 && dist2 > ans) {         ans = dist2;         a1 = t;       }       cout << ans <<   n ;     }     return 0;   }   