#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int L = 20;
int n, pre[N][L], lvl[N];
vector<int> adj[N];
int lca(int u, int v) {
  if (lvl[u] > lvl[v]) swap(u, v);
  for (int l = (int)(L)-1; l >= ((int)0); l--)
    if (lvl[pre[v][l]] >= lvl[u]) v = pre[v][l];
  if (u == v) return u;
  for (int l = (int)(L)-1; l >= ((int)0); l--)
    if (pre[u][l] != pre[v][l]) {
      u = pre[u][l];
      v = pre[v][l];
    }
  assert(u != v);
  return pre[u][0];
}
int cum[N];
int get(int x) {
  x += 2;
  int ans = 0;
  while (x) {
    ans += cum[x];
    x -= x & (-x);
  }
  return ans;
}
void add(int x, int delta) {
  x += 2;
  while (x < N) {
    cum[x] += delta;
    x += x & (-x);
  }
}
int t = 1, d[N], f[N];
void dfs(int u) {
  d[u] = t++;
  for (int v : adj[u]) dfs(v);
  f[u] = t;
}
struct edge {
  int u, v, c;
};
vector<edge> path[N];
int dp[N];
void dpDfs(int u) {
  int ans = 0;
  for (int v : adj[u]) {
    dpDfs(v);
    ans += dp[v];
  }
  int cost = 0;
  for (auto p : path[u]) {
    int add = p.c - get(d[p.u]) - get(d[p.v]);
    cost = max(cost, add);
  }
  dp[u] = ans + cost;
  add(d[u], cost);
  add(f[u], -cost);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> n >> m;
  for (int i = 0; i < (int)(n - 1); i++) {
    cin >> pre[i + 2][0];
    lvl[i + 2] = 1 + lvl[pre[i + 2][0]];
    adj[pre[i + 2][0]].push_back(i + 2);
  }
  pre[1][0] = 1;
  for (int l = 0; l < (int)(L - 1); l++)
    for (int u = 0; u < (int)(n + 1); u++) pre[u][l + 1] = pre[pre[u][l]][l];
  dfs(1);
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    int p = lca(u, v);
    path[p].push_back((edge){u, v, c});
  }
  dpDfs(1);
  cout << dp[1] << endl;
  return 0;
}
