func_code_string: #include <bits/stdc++.h>   namespace IO {   char buf[1000000], *p1, *p2;   inline char getc() {     if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);     return p1 == p2 ? EOF : *(p1++);   }   template <typename tp>   inline void r(tp &n) {     n = 0;     char c = getc();     while (!isdigit(c)) c = getc();     while (isdigit(c)) n = n * 10 + c - 48, c = getc();   }   template <typename tp, typename... Args>   inline void r(tp &n, Args &...args) {     r(n);     r(args...);   }   template <typename tp>   inline void write(tp n) {     if (n / 10) write(n / 10);     putchar(n % 10 + 48);   }   template <typename tp>   inline void w(tp n, char c =   n ) {     write(n);     putchar(c);   }   };  // namespace IO   using namespace IO;   const int N = 1e6 + 2333;   using namespace std;   int m;   int dep[N], f[N][25];   int LCA(int x, int y) {     if (dep[x] < dep[y]) x ^= y ^= x ^= y;     for (int i = 20; i >= 0; --i)       if (dep[f[x][i]] >= dep[y]) x = f[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; --i)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   int dis(int a, int b) { return dep[a] + dep[b] - dep[LCA(a, b)] * 2; }   int main() {     r(m);     int n = 4, u = 2, v = 3, nowdis = 2;     for (int i = 2; i <= 4; ++i) f[i][0] = 1, dep[i] = 1;     while (m--) {       int x;       r(x);       dep[n + 1] = dep[x] + 1, f[n + 1][0] = x;       dep[n + 2] = dep[x] + 1, f[n + 2][0] = x;       for (int i = 0; f[n + 1][i]; ++i) f[n + 1][i + 1] = f[f[n + 1][i]][i];       for (int i = 0; f[n + 2][i]; ++i) f[n + 2][i + 1] = f[f[n + 2][i]][i];       n += 2;       int a = dis(u, n), b = dis(v, n), c = nowdis;       nowdis = max(max(a, b), c);       if (nowdis == a)         v = n;       else if (nowdis == b)         u = n;       w(nowdis);     }     return 0;   }   