#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
typedef int ai[N];
vector<int> G[N];
int cnt;
ai s, h, top, pa, dfn, hea;
long long dp[N];
int size(int x, int p) {
  s[x] = 1;
  for (auto i : G[x]) s[x] += size(i, x);
  return s[x];
}
void dfs(int x, int p, int t) {
  pa[x] = p, top[x] = t, h[x] = h[p] + 1, dfn[x] = ++cnt;
  int &y = hea[x] = 0;
  for (auto i : G[x])
    if (s[y] < s[i]) y = i;
  if (y) dfs(y, x, t);
  for (auto i : G[x])
    if (i != y) dfs(i, x, i);
}
void build() {
  size(1, 0);
  cnt = 0;
  dfs(1, 0, 1);
}
long long tree[N];
long long query(int x) {
  int res = 0;
  while (x) {
    res += tree[x];
    x -= x & -x;
  }
  return res;
}
void add(int x, long long c) {
  while (x <= cnt) {
    tree[x] += c;
    x += x & -x;
  }
}
long long foo(int l, int r) { return query(r) - query(l - 1); }
long long path(int x, int y, int &w, int need) {
  int X = x, Y = y;
  long long res = 0;
  while (top[x] != top[y]) {
    if (h[top[x]] >= h[top[y]]) {
      if (need) res += foo(dfn[top[x]], dfn[x]);
      int u = pa[top[x]], v = top[x];
      x = pa[top[x]];
      if (hea[u]) res += dp[hea[u]] - dp[v];
    } else
      swap(x, y);
  }
  if (dfn[x] > dfn[y]) swap(x, y);
  if (need) res += foo(dfn[x], dfn[y]);
  w = x;
  if (hea[w]) res -= dp[hea[w]];
  if (hea[X]) res += dp[hea[X]];
  if (hea[Y]) res += dp[hea[Y]];
  return res;
}
vector<pair<pair<int, int>, int>> eve[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  build();
  vector<int> all;
  for (int i = 1; i <= n; ++i) all.push_back(i);
  sort(all.begin(), all.end(), [&](int i, int j) { return h[i] > h[j]; });
  for (int rr = 0; rr < m; ++rr) {
    int u, v, c, w;
    scanf("%d%d%d", &u, &v, &c);
    path(u, v, w, 0);
    eve[w].push_back({{u, v}, c});
  }
  for (int x : all) {
    dp[x] = 0;
    for (int u : G[x]) dp[x] += dp[u];
    for (auto e : eve[x]) {
      int c = e.second;
      int u = e.first.first;
      int v = e.first.second;
      int w;
      dp[x] = max(dp[x], c + path(u, v, w, 1));
    }
    int u = pa[x], v = x;
    if (u && v != hea[u]) add(dfn[u], dp[v]);
  }
  cout << dp[1] << endl;
}
