#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int par[18][100005];   int depth[100005];   void dfs(int u, int p = 0, int d = 0) {     par[0][u] = p;     depth[u] = d;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p) continue;       dfs(v, u, d + 1);     }   }   int LCA(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     int diff = depth[a] - depth[b];     for (int i = 17; i >= 0; i--)       if ((diff >> i) & 1) a = par[i][a];     if (a == b) return a;     for (int i = 17; i >= 0; i--) {       if (par[i][a] != par[i][b]) a = par[i][a], b = par[i][b];     }     return par[0][a];   }   int dist(int a, int b) {     int lca = LCA(a, b);     return depth[a] + depth[b] - 2 * depth[lca];   }   int main() {     int n, q, p;     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++)       scanf( %d , &p), g[i].push_back(p), g[p].push_back(i);     dfs(1);     for (int j = 1; j <= 17; j++)       for (int i = 1; i <= n; i++)         if (par[j - 1][i] != 0) par[j][i] = par[j - 1][par[j - 1][i]];     while (q--) {       int a[3];       scanf( %d%d%d , &a[0], &a[1], &a[2]);       int ans = -1;       for (int i = 0; i < 3; i++) {         for (int j = 0; j < 3; j++) {           for (int k = 0; k < 3; k++) {             if (i == j || i == k || j == k) continue;             int s = a[i], t = a[j], f = a[k];             ans = max(ans, (dist(s, f) + dist(t, f) - dist(s, t) + 1) / 2);           }         }       }       printf( %d n , ans + 1);     }   }   