#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
void reduce(int &a) { a += a >> 31 & mod; }
int Mod(const int &x) { return x >= mod ? x - mod : x; }
long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 200010, M = N;
int n, m, fa[N][20], dep[N], siz[N], id[N], dfn[N], dfs_clock;
;
struct edge {
  int nxt, to, w;
} e[M << 1];
int head[N], ecnt = 1;
void add(int u, int v, int w = 0) {
  e[++ecnt] = {head[u], v, w}, head[u] = ecnt;
}
void add_edge(int u, int v, int w = 0) { add(u, v, w), add(v, u, w * 1); };
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int h = dep[u] - dep[v];
  for (int i = 0; i < 20; i++)
    if (h & (1 << i)) u = fa[u][i];
  if (u == v) return u;
  for (int i = 19; ~i; i--)
    if (fa[u][i] != fa[v][i]) v = fa[v][i], u = fa[u][i];
  return fa[u][0];
}
void dfs(int u) {
  id[dfn[u] = ++dfs_clock] = u;
  for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  siz[u] = 1;
  for (int i = head[u], v; i; i = e[i].nxt)
    fa[v = e[i].to][0] = u, dep[v] = dep[u] + 1, dfs(v), siz[u] += siz[v];
}
vector<tuple<int, int, int> > vec[N];
int f[N], t[N];
void update(int l, int r, int v) {
  for (int i = l; i <= n; i += i & -i) t[i] += v;
  for (int i = r + 1; i <= n; i += i & -i) t[i] -= v;
}
int query(int i) {
  int res = 0;
  for (; i; i -= i & -i) res += t[i];
  return res;
}
void DP(int u) {
  int sum = 0;
  for (int i = head[u], v; i; i = e[i].nxt) DP(v = e[i].to), sum += f[v];
  f[u] = sum;
  for (auto i : vec[u]) {
    int x, y, w;
    tie(x, y, w) = i;
    f[u] = max(f[u], w + query(dfn[x]) + query(dfn[y]) + sum);
  }
  update(dfn[u], dfn[u] + siz[u] - 1, sum - f[u]);
}
int main() {
  n = read(), m = read();
  for (int i = 2; i <= n; i++) add(read(), i);
  dfs(1);
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), c = read();
    vec[lca(x, y)].push_back(make_tuple(x, y, c));
  }
  DP(1);
  ::print(f[1]), putchar('\n');
}
