#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, depth, timer;
long long t[4 * N], S[N], dp[N], Av, Bv;
int dep[N], in[N], out[N], a[N], b[N], vl[N], P[N][20];
vector<int> v[N], G[N];
void Dfs(int x) {
  dep[x] = ++depth;
  in[x] = ++timer;
  for (int i = 0; i < v[x].size(); ++i) {
    Dfs(v[x][i]);
  }
  out[x] = timer;
  --depth;
}
bool is_anc(int a, int b) { return (in[a] <= in[b] && out[b] <= out[a]); }
int LCA(int a, int b) {
  if (is_anc(a, b)) return a;
  for (int i = 18; i >= 0; i--) {
    if (!is_anc(P[a][i], b)) a = P[a][i];
  }
  return P[a][0];
}
int L, R, V;
void Upd(int h, int l, int r) {
  if (r < L || R < l) return;
  if (L <= l && r <= R) {
    t[h] += V;
    return;
  }
  Upd((h << 1), l, ((l + r) >> 1));
  Upd(((h << 1) | 1), ((l + r) >> 1) + 1, r);
}
int idx, id;
long long Get(int h, int l, int r) {
  if (r < idx || idx < l) return 0;
  if (l == idx && r == idx) return t[h];
  return Get((h << 1), l, ((l + r) >> 1)) +
         Get(((h << 1) | 1), ((l + r) >> 1) + 1, r) + t[h];
}
void Ufs(int x) {
  for (int i = 0; i < v[x].size(); ++i) {
    int to = v[x][i];
    Ufs(to);
    S[x] += dp[to];
  }
  dp[x] = S[x];
  for (int i = 0; i < G[x].size(); ++i) {
    id = G[x][i];
    idx = in[a[id]];
    Av = Get(1, 1, n);
    idx = in[b[id]];
    Bv = Get(1, 1, n);
    dp[x] = max(dp[x], S[x] + Av + Bv + vl[id]);
  }
  L = in[x];
  R = out[x];
  V = S[x] - dp[x];
  Upd(1, 1, n);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 2; i <= n; ++i) {
    cin >> P[i][0];
    v[P[i][0]].push_back(i);
  }
  P[1][0] = 1;
  for (int j = 1; j <= 18; ++j)
    for (int i = 1; i <= n; ++i) P[i][j] = P[P[i][j - 1]][j - 1];
  Dfs(1);
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i] >> vl[i];
    if (dep[a[i]] > dep[b[i]]) swap(a[i], b[i]);
    G[LCA(a[i], b[i])].push_back(i);
  }
  Ufs(1);
  printf("%d\n", dp[1]);
}
