func_code_string: #include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[131072], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 131072, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int& x) {     x = 0;     char c = gc();     while (c <  0  || c >  9 ) c = gc();     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = gc();     }   }   int fa[100003], son[100003][2], st[100003], a[100003], sum[100003],       size[100003], tag[100003];   bool rev[100003];   int n, q;   inline void pushup(int u) {     sum[u] = sum[son[u][0]] + sum[son[u][1]] + a[u];     size[u] = size[son[u][0]] + size[son[u][1]] + 1;   }   inline bool notrt(const int& u) {     return son[fa[u]][0] == u || son[fa[u]][1] == u;   }   inline void pushr(const int& u) {     swap(son[u][0], son[u][1]);     rev[u] ^= 1;   }   inline void pushc(const int& u, const int& k) {     a[u] = tag[u] = k;     sum[u] = k == 0 ? 0 : size[u];   }   inline void pushdown(const int& u) {     if (tag[u] != -1) {       if (son[u][0]) pushc(son[u][0], tag[u]);       if (son[u][1]) pushc(son[u][1], tag[u]);       tag[u] = -1;     }     if (!rev[u]) return;     if (son[u][0]) pushr(son[u][0]);     if (son[u][1]) pushr(son[u][1]);     rev[u] = 0;   }   inline void rotate(const int& x) {     int y = fa[x], z = fa[y];     int k = son[y][1] == x, w = son[x][k ^ 1];     if (notrt(y)) son[z][son[z][1] == y] = x;     son[x][k ^ 1] = y;     son[y][k] = w;     if (w) fa[w] = y;     fa[y] = x, fa[x] = z;     pushup(y);   }   inline void splay(const int& x) {     register int y = x, z = 0;     st[++z] = y;     while (notrt(y)) st[++z] = y = fa[y];     while (z) pushdown(st[z--]);     while (notrt(x)) {       y = fa[x], z = fa[y];       if (notrt(y)) rotate((son[z][1] == y) == (son[y][1] == x) ? y : x);       rotate(x);     }     pushup(x);   }   inline void access(int u) {     for (register int v = 0; u; u = fa[u]) {       splay(u), son[u][1] = v;       pushup(u), v = u;     }   }   inline void makeroot(int u) {     access(u), splay(u);     pushr(u);   }   inline void link(int u, int v) {     makeroot(u);     fa[u] = v;   }   inline void split(int u, int v) {     makeroot(u);     access(v), splay(v);   }   inline int check(int u1, int v1, int u2, int v2) {     split(u1, v1), pushc(v1, 1);     split(u2, v2);     int res = sum[v2];     split(u1, v1), pushc(v1, 0);     return res;   }   int main() {     int x, y, z, ans;     read(n), read(q);     for (register int i = 1; i <= n; ++i) tag[i] = -1;     for (register int i = 2; i <= n; ++i) {       read(x);       link(x, i);     }     while (q--) {       read(x), read(y), read(z);       ans = check(x, y, x, z);       ans = max(ans, check(x, y, y, z));       ans = max(ans, check(x, z, y, z));       printf( %d n , ans);     }     return 0;   }   