#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
int stt[MAXN], fnt[MAXN], ras[MAXN], timer = 1;
int par[MAXN], head[MAXN], h[MAXN], sz[MAXN];
int dp[MAXN], sum[MAXN];
long long fen[MAXN];
vector<int> G[MAXN];
vector<pair<pair<int, int>, int> > vec[MAXN];
void dfs1(int node, int hd) {
  ras[stt[node] = timer++] = node;
  head[node] = hd;
  int big = 0;
  for (int v : G[node])
    if (sz[v] > sz[big]) big = v;
  if (big) dfs1(big, hd);
  for (int v : G[node])
    if (v != big) dfs1(v, v);
  fnt[node] = timer;
}
inline int Lca(int x, int y) {
  while (head[x] != head[y]) {
    if (h[head[x]] < h[head[y]]) swap(x, y);
    x = par[head[x]];
  }
  if (h[x] > h[y]) swap(x, y);
  return x;
}
inline void add(int pos, int x) {
  for (; pos < MAXN; pos += pos & -pos) fen[pos] += x;
}
inline int get(int pos) {
  int res = 0;
  for (; pos; pos -= pos & -pos) res += fen[pos];
  return res;
}
void dfs2(int node) {
  for (int v : G[node]) {
    dfs2(v);
    sum[node] += dp[v];
  }
  dp[node] = sum[node];
  for (pair<pair<int, int>, int> p : vec[node]) {
    int tmp = get(stt[p.first.first]) + get(stt[p.first.second]);
    tmp += sum[node] + p.second;
    dp[node] = max(dp[node], tmp);
  }
  add(stt[node], sum[node] - dp[node]);
  add(fnt[node], dp[node] - sum[node]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 2; i <= n; i++)
    cin >> par[i], h[i] = h[par[i]] + 1, G[par[i]].push_back(i);
  for (int i = n; i > 1; i--) sz[par[i]] += ++sz[i];
  dfs1(1, 1);
  while (m--) {
    cin >> u >> v >> x;
    vec[Lca(u, v)].push_back({{u, v}, x});
  }
  dfs2(1);
  cout << dp[1] << '\n';
  return 0;
}
