#include <bits/stdc++.h>
std::vector<int> E[200001];
std::vector<std::pair<std::pair<int, int>, int> > Path[200001];
int N, M, left[200001], right[200001], ref[200001], J[18][200001],
    *fa = J[0], LOG, dep[200001];
long long F[200001], T[524288], O;
void DFS() {
  static int q[200001];
  static std::vector<int>::iterator ue[200001];
  int D = 1, TIME = 1;
  q[1] = 1;
  ue[1] = E[1].begin();
  ref[left[1] = right[1] = 1] = 1;
  while (D)
    if (ue[D] != E[q[D]].end()) {
      int To = *ue[D]++;
      ref[left[To] = right[To] = ++TIME] = To;
      q[++D] = To;
      ue[D] = E[To].begin();
    } else {
      if (D > 1) right[q[D - 1]] = right[q[D]];
      D--;
    }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) std::swap(u, v);
  for (int i = LOG; ~i; i--)
    if (dep[u] - dep[v] >= 1 << i) u = J[i][u];
  if (u == v) return u;
  for (int i = LOG; ~i; i--)
    if (J[i][u] != J[i][v]) {
      u = J[i][u];
      v = J[i][v];
    }
  return fa[u];
}
long long G(int x) {
  int p = 1, l = 1, r = N;
  while (l < r) {
    int m = l + r >> 1;
    if (x <= m)
      p <<= 1, r = m;
    else
      p = p << 1 | 1, l = m + 1;
  }
  long long S = 0;
  while (p) {
    S += T[p];
    p >>= 1;
  }
  return S;
}
void P(int p, int l, int r, int L, int R, long long w) {
  if (L <= l && r <= R) {
    T[p] += w;
    return;
  }
  int m = l + r >> 1;
  if (L <= m) P(p << 1, l, m, L, R, w);
  if (R > m) P(p << 1 | 1, m + 1, r, L, R, w);
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 2; i <= N; i++) {
    scanf("%d", fa + i);
    E[fa[i]].push_back(i);
    dep[i] = dep[fa[i]] + 1;
  }
  while (2 << LOG < N) LOG++;
  for (int i = 1; i <= LOG; i++)
    for (int j = 1; j <= N; j++) J[i][j] = J[i - 1][J[i - 1][j]];
  DFS();
  while (M--) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    int lca = LCA(u, v);
    Path[lca].push_back({{u, v}, c});
  }
  for (int i = N; i; i--) {
    int u = ref[i];
    F[u] = 0;
    for (auto p : Path[u])
      F[u] = std::max(
          F[u], p.second - G(left[p.first.first]) - G(left[p.first.second]));
    P(1, 1, N, left[u], right[u], F[u]);
    O += F[u];
  }
  printf("%lld\n", O);
  return 0;
}
