#include <bits/stdc++.h>
using namespace std;
const int maxn = 201000, MAXD = 18;
int n, m, ans, stamp, l[maxn], r[maxn], f[maxn][MAXD + 1], dep[maxn];
int g[maxn], gg[maxn];
long long tree[maxn];
struct edge {
  int u, v, w;
};
vector<int> G[maxn];
vector<edge> P[maxn];
void dfs(int u) {
  l[u] = ++stamp;
  dep[u] = dep[f[u][0]] + 1;
  for (int i = 1; i <= MAXD; ++i) f[u][i] = f[f[u][i - 1]][i - 1];
  for (auto v : G[u]) dfs(v);
  r[u] = stamp;
}
inline int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = MAXD; i >= 0; --i)
    if (dep[f[u][i]] >= dep[v]) u = f[u][i];
  if (u == v) return u;
  for (int i = MAXD; i >= 0; --i)
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  return f[u][0];
}
inline void modify(int x, int delta) {
  while (x <= n) {
    tree[x] += delta;
    x += x & (-x);
  }
}
inline int query(int x) {
  long long ret = 0;
  while (x) {
    ret += tree[x];
    x -= x & (-x);
  }
  return ret;
}
inline int getfa(int u, int d) {
  for (int i = MAXD; i >= 0; --i)
    if (d >= (1 << i)) {
      d ^= 1 << i;
      u = f[u][i];
    }
  return u;
}
void solve(int u) {
  for (auto v : G[u]) {
    solve(v);
    gg[u] += g[v];
  }
  g[u] = gg[u];
  for (auto item : P[u]) {
    if (item.v == u) swap(item.u, item.v);
    int f1 = getfa(item.u, dep[item.u] - dep[u] - 1),
        f2 = getfa(item.v, dep[item.v] - dep[u] - 1);
    if (item.u == u) {
      g[u] =
          max(g[u], (gg[u] - g[f2]) + query(l[item.v]) + gg[item.v] + item.w);
    } else {
      g[u] = max(g[u], (gg[u] - g[f1] - g[f2]) + query(l[item.u]) + gg[item.u] +
                           query(l[item.v]) + gg[item.v] + item.w);
    }
  }
  for (auto v : G[u]) {
    modify(l[v], gg[u] - g[v]);
    modify(r[v] + 1, -(gg[u] - g[v]));
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    G[i].clear();
    P[i].clear();
  }
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
    f[i][0] = p;
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) tree[i] = 0;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    P[getlca(u, v)].push_back((edge){u, v, w});
  }
  solve(1);
  printf("%d\n", g[1]);
}
