func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const int maxm = 100000 + 10;   vector<int> adj[maxn];   int fa[maxn][18], dep[maxn];   void trans(int prev, int u) {     dep[u] = dep[prev] + 1;     fa[u][0] = prev;     for (int i = 1; (1 << i) <= dep[u]; i++) {       fa[u][i] = fa[fa[u][i - 1]][i - 1];     }     int len = adj[u].size();     for (int i = 0; i < len; i++) {       int v = adj[u][i];       if (v == prev) continue;       trans(u, v);     }   }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     for (int i = 0; (1 << i) <= dep[v] - dep[u]; i++) {       if ((dep[v] - dep[u]) & 1 << i) v = fa[v][i];     }     if (u == v) return u;     for (int i = 18; i >= 0; i--) {       if ((1 << i) <= dep[u] && fa[u][i] != fa[v][i]) {         u = fa[u][i];         v = fa[v][i];       }     }     return fa[u][0];   }   int dis(int u, int v) {     int fff = lca(u, v);     return dep[u] + dep[v] - 2 * dep[fff];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       int j;       scanf( %d , &j);       adj[i].push_back(j);       adj[j].push_back(i);     }     dep[1] = 0;     trans(1, 1);     for (int i = 0; i < m; i++) {       int q[3];       for (int i = 0; i < 3; i++) scanf( %d , &q[i]);       int a[3], ttt = 0;       for (int i = 0; i < 3; i++) {         for (int j = i + 1; j < 3; j++) {           a[ttt++] = lca(q[i], q[j]);         }       }       int k = 0;       for (int i = 0; i < 3; i++)         if (dep[a[i]] > dep[a[k]]) k = i;       k = a[k];       int ans = 0;       for (int i = 0; i < 3; i++) ans = max(ans, dis(k, q[i]));       printf( %d n , ans + 1);     }     return 0;   }   