#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 2e5 + 500;
const long long logg = 22;
long long par[maxn][logg];
long long dpsum[maxn][logg];
long long childsum[maxn][logg];
vector<long long> child[maxn];
long long s[maxn];
long long e[maxn];
long long timee = 0;
pair<long long, pair<long long, long long> > r[maxn];
vector<long long> kk[maxn];
long long dp[maxn];
bool pr = 0;
bool is_par(long long a, long long b) {
  if (s[a] <= s[b] && e[a] >= e[b]) return 1;
  return 0;
}
long long lca(long long a, long long b) {
  if (is_par(a, b)) {
    return a;
  }
  if (is_par(b, a)) {
    return b;
  }
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      a = par[a][i];
    }
  }
  return par[a][0];
}
long long lcaa(long long a, long long b) {
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      a = par[a][i];
    }
  }
  return a;
}
void set_se(long long a) {
  s[a] = timee;
  timee++;
  for (long long i = 0; i < child[a].size(); i++) {
    set_se(child[a][i]);
  }
  e[a] = timee;
  timee++;
}
void set_dpsum(long long a, long long i) {
  if (dpsum[a][i] != -1) {
    return;
  }
  long long v = par[a][i - 1];
  set_dpsum(v, i - 1);
  set_dpsum(a, i - 1);
  dpsum[a][i] = dpsum[a][i - 1] + dpsum[v][i - 1];
}
long long lcas(long long a, long long b) {
  if (a == b) {
    return 0;
  }
  long long ans = 0;
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      set_dpsum(a, i);
      ans += dpsum[a][i];
      a = par[a][i];
    }
  }
  return ans + dp[a];
}
void set_childsum(long long a, long long i) {
  if (childsum[a][i] != -1) {
    return;
  }
  long long v = par[a][i - 1];
  set_childsum(v, i - 1);
  set_childsum(a, i - 1);
  childsum[a][i] = childsum[a][i - 1] + childsum[v][i - 1];
}
long long lcaaa(long long a, long long b) {
  if (a == b) {
    return 0;
  }
  long long ans = 0;
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      set_childsum(a, i);
      ans += childsum[a][i];
      a = par[a][i];
    }
  }
  return ans + childsum[a][0];
}
void dfs(long long a) {
  long long sum = 0;
  for (long long i = 0; i < child[a].size(); i++) {
    dfs(child[a][i]);
    sum += dp[child[a][i]];
  }
  childsum[a][0] = sum;
  dp[a] = sum;
  for (long long i = 0; i < kk[a].size(); i++) {
    long long v = r[kk[a][i]].second.first;
    long long u = r[kk[a][i]].second.second;
    if (v == a || u == a) {
      v = v ^ a ^ u;
      long long ss = sum;
      long long vv = lcaa(v, a);
      ss -= dp[vv];
      ss += r[kk[a][i]].first;
      ss -= lcas(v, vv);
      ss += lcaaa(v, a);
      dp[a] = max(dp[a], ss);
    } else {
      long long ss = sum;
      long long uu = lcaa(u, a);
      long long vv = lcaa(v, a);
      ss -= dp[uu];
      ss -= dp[vv];
      ss += r[kk[a][i]].first;
      ss -= lcas(v, vv);
      ss -= lcas(u, uu);
      ss += lcaaa(v, a);
      ss += lcaaa(u, a);
      dp[a] = max(dp[a], ss);
    }
  }
  dpsum[a][0] = dp[a];
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n; i++) {
    long long v;
    cin >> v;
    v--;
    par[i][0] = v;
    child[v].push_back(i);
  }
  set_se(0);
  par[0][0] = 0;
  for (long long i = 1; i < logg; i++) {
    for (long long j = 0; j < n; j++) {
      par[j][i] = par[par[j][i - 1]][i - 1];
    }
  }
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    v--;
    u--;
    r[i] = make_pair(w, make_pair(u, v));
    kk[lca(v, u)].push_back(i);
  }
  for (long long i = 0; i < logg; i++) {
    for (long long j = 0; j < n; j++) {
      dpsum[j][i] = -1;
      childsum[j][i] = -1;
    }
  }
  dfs(0);
  for (long long i = 0; i < 1; i++) {
    cout << dp[i] << "   ";
  }
}
