#include <bits/stdc++.h>
using namespace std;
struct ST {
  long long val[800010];
  void pushdown(int root) {
    val[root << 1] += val[root];
    val[root << 1 | 1] += val[root];
    val[root] = 0;
    return;
  }
  void add(int root, int l, int r, int x, int y, long long z) {
    if (x <= l && r <= y) {
      val[root] += z;
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(root);
    if (x <= mid) add(root << 1, l, mid, x, y, z);
    if (y > mid) add(root << 1 | 1, mid + 1, r, x, y, z);
    return;
  }
  long long query(int root, int l, int r, int x) {
    if (l == r) return val[root];
    int mid = (l + r) >> 1;
    pushdown(root);
    if (x <= mid)
      return query(root << 1, l, mid, x);
    else
      return query(root << 1 | 1, mid + 1, r, x);
  }
} S, T;
int n, m;
int dfn[200010], to[200010], now;
long long f[200010], sum[200010];
vector<int> e[200010];
const int M = 20;
int fa[200010][20];
int dep[200010];
void init() {
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  return;
}
int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int need = dep[u] - dep[v], cur = 0;
  while (need) {
    if (need & 1) u = fa[u][cur];
    cur++;
    need >>= 1;
  }
  if (u == v) return u;
  for (int i = M - 1; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
struct Path {
  int u, v, c;
  Path(int uu = 0, int vv = 0, int cc = 0) {
    u = uu;
    v = vv;
    c = cc;
  }
};
vector<Path> vec[200010];
void dfs(int u) {
  dfn[u] = ++now;
  sum[u] = 0;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    dfs(v);
    sum[u] += f[v];
  }
  to[u] = now;
  f[u] = sum[u];
  for (int i = 0; i < vec[u].size(); i++) {
    int p = vec[u][i].u;
    int q = vec[u][i].v;
    int c = vec[u][i].c;
    long long val = sum[u] + c;
    val += S.query(1, 1, n, dfn[p]) - T.query(1, 1, n, dfn[p]);
    val += S.query(1, 1, n, dfn[q]) - T.query(1, 1, n, dfn[q]);
    f[u] = max(f[u], val);
  }
  S.add(1, 1, n, dfn[u], to[u], sum[u]);
  T.add(1, 1, n, dfn[u], to[u], f[u]);
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  dep[1] = 1;
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    e[p].push_back(i);
    fa[i][0] = p;
    dep[i] = dep[p] + 1;
  }
  init();
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    int lca = getlca(u, v);
    vec[lca].push_back(Path(u, v, c));
  }
  dfs(1);
  printf("%I64d\n", f[1]);
  return 0;
}
