#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.2")
using namespace std;
inline void opting() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
long long inp() {
  long long x;
  cin >> x;
  return x;
}
void make_unique(vector<long long> &vec, bool sorted = false) {
  if (!sorted) sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
}
void file_edit(bool reader = true, bool writer = false) {
  if (reader) freopen("Test_input.txt", "r", stdin);
  if (writer) freopen("Test_output.txt", "w", stdout);
}
const int SQRT = 65, lg = 18 + 2, inlim = 2147483647;
const int maxn = 2e5 + 20, delta = 1e9 + 7, inf = 1e9 + 420;
char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
const int N = 200010;
const int M = 19;
int h[N], nx[N << 1], t[N << 1], num;
int c[N];
int F[N][M];
int d[N], L[N], R[N], f[N], cnt;
int u[N], v[N], w[N];
vector<int> a[N];
int k, n, m, Ans;
void Add(int x, int y) {
  t[++num] = y;
  nx[num] = h[x];
  h[x] = num;
}
void Dfs(int x) {
  d[x] = d[F[x][0]] + 1;
  for (int i = 1; i < M; i++) F[x][i] = F[F[x][i - 1]][i - 1];
  L[x] = ++cnt;
  for (int i = h[x]; i; i = nx[i]) Dfs(t[i]);
  R[x] = cnt;
}
int Lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = M - 1; ~i; i--)
    if (d[F[x][i]] >= d[y]) x = F[x][i];
  if (x == y) return x;
  for (int i = M - 1; ~i; i--)
    if (F[x][i] != F[y][i]) x = F[x][i], y = F[y][i];
  return F[x][0];
}
void Update(int x, int y) {
  for (; x <= n; x += x & -x) c[x] += y;
}
int Query(int x) {
  int Ans = 0;
  for (; x; x -= x & -x) Ans += c[x];
  return Ans;
}
void Up(int l, int r, int y) {
  Update(l, y);
  Update(r + 1, -y);
}
void Solve(int x) {
  int S = 0;
  for (int i = h[x]; i; i = nx[i]) {
    Solve(t[i]);
    S += f[t[i]];
  }
  f[x] = S;
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    f[x] = max(f[x], Query(L[u[y]]) + Query(L[v[y]]) + S + w[y]);
  }
  Up(L[x], R[x], S - f[x]);
}
int main() {
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    cin >> F[i][0];
    Add(F[i][0], i);
  }
  Dfs(1);
  for (int i = 1; i <= m; i++)
    cin >> u[i] >> v[i] >> w[i], a[Lca(u[i], v[i])].push_back(i);
  Solve(1);
  cout << f[1] << endl;
  return 0;
}
