func_code_string: #include <bits/stdc++.h>   using namespace std;   int lg[1000005], jump[1000005][20], depth[1000005], head[1000005], cnt = 4;   int q, tot, s, t, zj;   struct edge {     int to, next;   } e[2000005];   void add(int x, int y) {     e[++tot].to = y;     e[tot].next = head[x];     head[x] = tot;   }   void dfs(int now, int fa) {     for (int i = head[now]; i; i = e[i].next) {       if (e[i].to != fa) {         dfs(e[i].to, now);       }     }   }   int LCA(int x, int y) {     if (depth[x] < depth[y]) {       swap(x, y);     }     while (depth[x] > depth[y]) {       x = jump[x][lg[depth[x] - depth[y]] - 1];     }     if (x == y) {       return x;     }     for (int i = lg[depth[x]] - 1; i >= 0; i--) {       if (jump[x][i] != jump[y][i]) {         x = jump[x][i];         y = jump[y][i];       }     }     return jump[x][0];   }   int dis(int a, int b) {     int lca = LCA(a, b);     return depth[a] + depth[b] - 2 * depth[lca];   }   int main() {     ios::sync_with_stdio(false);     cin >> q;     for (int i = 1; i <= q * 2 + 4; i++) {       lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);     }     add(1, 2), add(1, 3), add(1, 4);     jump[2][0] = jump[3][0] = jump[4][0] = 1;     depth[1] = 1, depth[2] = depth[3] = depth[4] = 2;     s = 2, t = 4, zj = 2;     for (int i = 0; i < q; i++) {       int v;       cin >> v;       cnt++;       add(v, cnt);       add(cnt, v);       depth[cnt] = depth[v] + 1;       jump[cnt][0] = v;       for (int j = 1; j <= lg[depth[cnt]]; j++) {         jump[cnt][j] = jump[jump[cnt][j - 1]][j - 1];       }       if (dis(cnt, s) > dis(s, t)) {         t = cnt;         zj = dis(cnt, s);       }       if (dis(cnt, t) > dis(s, t)) {         s = cnt;         zj = dis(cnt, t);       }       cnt++;       add(v, cnt);       add(cnt, v);       depth[cnt] = depth[v] + 1;       jump[cnt][0] = v;       for (int j = 1; j <= lg[depth[cnt]]; j++) {         jump[cnt][j] = jump[jump[cnt][j - 1]][j - 1];       }       if (dis(cnt, s) > dis(s, t)) {         t = cnt;         zj = dis(cnt, s);       }       if (dis(cnt, t) > dis(s, t)) {         s = cnt;         zj = dis(cnt, t);       }       cout << zj << endl;     }   }   