#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Edge {
  int u, v, Next;
} G[200010];
int head[200010], tot, n, m;
int h[200010], Top[200010], Fa[200010], Size[200010], mx[200010];
int num[200010], mp[200010], cnt, C[200010], f[200010];
vector<pair<pair<int, int>, int> > op[200010];
inline void add(int u, int v) {
  G[++tot] = (Edge){u, v, head[u]};
  head[u] = tot;
}
inline void Add(int x, int y) {
  for (; x <= n; x += (x & -x)) {
    C[x] += y;
  }
}
inline int Query(int x) {
  int ret = 0;
  for (; x > 0; x -= (x & -x)) {
    ret += C[x];
  }
  return ret;
}
inline int ask(int x, int y) { return Query(y) - Query(x - 1); }
inline void dfs(int x, int f, int hei) {
  h[x] = hei;
  Fa[x] = f;
  Size[x] = 1;
  for (int i = head[x]; i != -1; i = G[i].Next) {
    dfs(G[i].v, x, hei + 1);
    Size[x] += Size[G[i].v];
    if (Size[G[i].v] > Size[mx[x]]) mx[x] = G[i].v;
  }
}
inline void dfs2(int x) {
  mp[num[x] = ++cnt] = x;
  if (mx[x]) Top[mx[x]] = Top[x], dfs2(mx[x]);
  for (int i = head[x]; i != -1; i = G[i].Next) {
    if (G[i].v == mx[x]) continue;
    Top[G[i].v] = G[i].v;
    dfs2(G[i].v);
  }
}
inline int lca(int x, int y) {
  while (Top[x] != Top[y]) {
    if (h[Top[x]] < h[Top[y]]) swap(x, y);
    x = Fa[Top[x]];
  }
  return h[x] < h[y] ? x : y;
}
inline int query(int x, int y) {
  if (h[Top[x]] < h[Top[y]]) return 0;
  int ret = 0;
  while (Top[x] != Top[y]) {
    ret += ask(num[Top[x]], num[x]) + f[mx[x]] - f[Top[x]];
    x = Fa[Top[x]];
  }
  ret += ask(num[y], num[x]) + f[mx[x]];
  return ret;
}
inline int last(int x, int y) {
  while (Top[x] != Top[y]) {
    if (Fa[Top[x]] == y) return Top[x];
    x = Fa[Top[x]];
  }
  return mp[num[y] + 1];
}
inline void dp(int x) {
  for (int i = head[x]; i != -1; i = G[i].Next) {
    dp(G[i].v);
    f[x] += f[G[i].v];
  }
  Add(num[x], f[x] - f[mx[x]]);
  for (int i = 0; i < op[x].size(); i++) {
    int u = last(op[x][i].first.first, x);
    int res = query(op[x][i].first.first, u) + query(op[x][i].first.second, x);
    res -= f[u] - op[x][i].second;
    f[x] = max(f[x], res);
  }
}
int main() {
  n = read(), m = read();
  Top[1] = 1;
  memset(head, -1, sizeof(head));
  for (int i = (2); i <= (n); i++) {
    int p = read();
    add(p, i);
  }
  dfs(1, 0, 1);
  dfs2(1);
  for (int i = (1); i <= (m); i++) {
    pair<pair<int, int>, int> t;
    t.first.first = read();
    t.first.second = read();
    t.second = read();
    if (h[t.first.first] < h[t.first.second])
      swap(t.first.first, t.first.second);
    op[lca(t.first.first, t.first.second)].push_back(t);
  }
  dp(1);
  cout << f[1] << endl;
  return 0;
}
