#include <bits/stdc++.h>
using namespace std;
const int M = 400400;
int to[M], fi[M], la[M], tot, dep[M], fa[M], siz[M], son[M], sum[M], f[M],
    sf[M], top[M], n, m, x, y, z, ne[M];
struct node {
  int x, y, z;
  node(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
};
vector<node> g[M / 2];
void add(int x, int y) {
  to[++tot] = y;
  !fi[x] ? fi[x] = tot : ne[la[x]] = tot;
  la[x] = tot;
}
void dfs(int x, int par) {
  fa[x] = par;
  dep[x] = dep[par] + 1;
  siz[x] = 1;
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == par) continue;
    dfs(v, x);
    siz[x] += siz[v];
    if (siz[v] > siz[son[x]]) son[x] = v;
  }
}
void link(int x, int tp) {
  top[x] = tp;
  if (son[x]) link(son[x], tp);
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == fa[x] || v == son[x]) continue;
    link(v, v);
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] > dep[top[y]])
      x = fa[top[x]];
    else
      y = fa[top[y]];
  }
  return dep[x] > dep[y] ? y : x;
}
int calc(int x, int y) {
  int ans = 0;
  while (top[y] != top[x]) {
    ans += sum[top[x]] - sum[son[x]] - (sf[top[x]] - sf[son[x]]);
    x = fa[top[x]];
  }
  ans += sum[y] - sum[son[x]] - (sf[son[y]] - sf[son[x]]);
  return ans;
}
void solve(int x) {
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == fa[x]) continue;
    solve(v);
    sum[x] += f[v];
  }
  f[x] = sum[x];
  sum[x] += sum[son[x]];
  for (int i = 0; i < g[x].size(); i++) {
    f[x] = max(f[x], calc(g[x][i].x, x) + calc(g[x][i].y, x) - sum[x] +
                         sum[son[x]] + g[x][i].z);
  }
  sf[x] = f[x] + sf[son[x]];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    add(i, x);
    add(x, i);
  }
  dfs(1, 0);
  link(1, 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    g[lca(x, y)].push_back(node(x, y, z));
  }
  solve(1);
  printf("%d\n", f[1]);
  return 0;
}
