#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m, x, y, k, ancestor[N], fa[N], fi[N], u[N], v[N], sum[N], dp[N],
    ne[N << 1], b[N << 1], money[N], sz[N], top[N], son[N], contribution[N];
vector<pair<int, int> > g[N];
vector<int> w[N];
inline void add(int x, int y) {
  b[++k] = y;
  ne[k] = fi[x];
  fi[x] = k;
}
inline int ask(int x) {
  return x == ancestor[x] ? x : ancestor[x] = ask(ancestor[x]);
}
inline int ask2(int x) { return x == top[x] ? x : top[x] = ask2(top[x]); }
inline void dfs(int x) {
  sz[x] = 1;
  for (int j = fi[x]; j; j = ne[j]) {
    fa[b[j]] = x;
    dfs(b[j]);
    ancestor[b[j]] = x;
    sz[x] += sz[b[j]];
    if (sz[b[j]] > sz[son[x]]) son[x] = b[j];
  }
  top[son[x]] = x;
  for (vector<pair<int, int> >::iterator it = g[x].begin(); it != g[x].end();
       it++)
    if (it->second == 1 || fa[it->second])
      w[ask(it->second)].push_back(it->first);
}
int calc(int i, int x) {
  int y = u[i], z = v[i], res = sum[y] + sum[z];
  while (top[y] != top[x])
    res +=
        contribution[top[y]] - contribution[y] + sum[fa[top[y]]] - dp[top[y]],
        y = fa[top[y]];
  res += contribution[x] - contribution[y];
  while (top[z] != top[x])
    res +=
        contribution[top[z]] - contribution[z] + sum[fa[top[z]]] - dp[top[z]],
        z = fa[top[z]];
  res += contribution[x] - contribution[z];
  return res - sum[x] + money[i];
}
void getans(int x) {
  for (int j = fi[x]; j; j = ne[j]) {
    getans(b[j]);
    sum[x] += dp[b[j]];
  }
  dp[x] = sum[x];
  contribution[x] = contribution[son[x]] + sum[x] - dp[son[x]];
  for (vector<int>::iterator it = w[x].begin(); it != w[x].end(); it++)
    dp[x] = max(dp[x], calc(*it, x));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    add(x, i);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u[i], &v[i], &money[i]);
    g[u[i]].push_back(make_pair(i, v[i]));
    g[v[i]].push_back(make_pair(i, u[i]));
  }
  for (int i = 1; i <= n; i++) ancestor[i] = top[i] = i;
  dfs(1);
  for (int i = 1; i <= n; i++) ask2(i);
  for (int i = 1; i <= n; i++)
    w[i].erase(unique(w[i].begin(), w[i].end()), w[i].end());
  getans(1);
  printf("%d", dp[1]);
}
