func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   int nowarn;   int n, m;   namespace Tree {   int head[MAXN], nxt[MAXN], to[MAXN], eidx;   void init() {     eidx = 0;     memset(head, -1, sizeof(head));   }   void adde(int u, int v) { to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++; }   }  // namespace Tree   namespace DFN {   int dfn[MAXN], dfn_cnt, son[MAXN], dep[MAXN], top[MAXN], size[MAXN], pa[MAXN];   void dfs1(int u, int fa, int d) {     using namespace Tree;     pa[u] = fa, dep[u] = d, son[u] = 0, size[u] = 1;     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       dfs1(v, u, d + 1);       size[u] += size[v];       if (size[v] > size[son[u]]) son[u] = v;     }   }   void dfs2(int u, int tp) {     using namespace Tree;     top[u] = tp, dfn[u] = ++dfn_cnt;     if (son[u]) dfs2(son[u], tp);     for (int i = head[u]; ~i; i = nxt[i]) {       int v = to[i];       if (v == son[u]) continue;       dfs2(v, v);     }   }   void prelude() {     size[0] = dfn_cnt = 0;     dfs1(1, 0, 1);     dfs2(1, 1);   }   int lca(int u, int v) {     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       u = pa[top[u]];     }     return min(u, v);   }   }  // namespace DFN   int lowbit(int x) { return x & (-x); }   struct BIT {     long long c[MAXN];     void init() { memset(c, 0, sizeof(c)); }     void add(int p, long long v) {       for (; p <= n; p += lowbit(p)) c[p] += v;     }     long long sum(int p) const {       long long s = 0;       for (; p; p -= lowbit(p)) s += c[p];       return s;     }     long long sum(int l, int r) const { return sum(r) - sum(l - 1); }   };   struct Triple {     int first, second, val;     Triple() {}     Triple(int a, int b, int c) : first(a), second(b), val(c) {}   };   vector<Triple> chain[MAXN];   BIT sf, sg;   long long query(int u, int v, const BIT &bit) {     using namespace DFN;     long long s = 0;     while (top[u] != top[v]) {       s += bit.sum(dfn[top[v]], dfn[v]);       v = pa[top[v]];     }     s += bit.sum(dfn[u], dfn[v]);     return s;   }   long long f[MAXN], g[MAXN];   void dp(int u) {     using namespace Tree;     using namespace DFN;     g[u] = 0;     for (int i = head[u]; ~i; i = nxt[i]) dp(to[i]), g[u] += f[to[i]];     sg.add(dfn[u], g[u]);     f[u] = g[u];     for (int i = 0; i < (int)chain[u].size(); ++i) {       Triple tp = chain[u][i];       int s = tp.first, t = tp.second, w = tp.val;       if (t == u) swap(s, t);       if (s == u) {         f[u] = max(f[u], query(u, t, sg) - query(u, t, sf) + w);       } else {         f[u] = max(f[u], query(u, s, sg) + query(u, t, sg) - g[u] -                              query(u, s, sf) - query(u, t, sf) + w);       }     }     sf.add(dfn[u], f[u]);   }   int main() {     nowarn = scanf( %d%d , &n, &m);     Tree::init();     for (int i = 2; i <= n; ++i) {       int p;       nowarn = scanf( %d , &p);       Tree::adde(p, i);     }     DFN::prelude();     while (m--) {       int u, v, w;       nowarn = scanf( %d%d%d , &u, &v, &w);       int lca = DFN::lca(u, v);       chain[lca].push_back(Triple(u, v, w));     }     sf.init(), sg.init();     dp(1);     printf( %lld n , f[1]);     return 0;   }   