#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "inline")
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int N = 200005;
int n, m;
vector<int> e[N], id[N];
struct Edge {
  int x, y, z;
} a[N];
int depth[N], size[N], son[N], fa[N], top[N], I[N], aI[N], Time = 0;
void dfs1(int x, int pre, int d) {
  depth[x] = d, fa[x] = pre, size[x] = 1, son[x] = 0;
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y != pre) {
      dfs1(y, x, d + 1);
      size[x] += size[y];
      if (!son[x] || size[y] > size[son[x]]) son[x] = y;
    }
  }
}
void dfs2(int x, int Top) {
  top[x] = Top;
  I[x] = ++Time;
  aI[Time] = x;
  if (son[x]) dfs2(son[x], Top);
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y != fa[x] && y != son[x]) dfs2(y, y);
  }
}
long long c[N];
void Add(int x, long long v) {
  for (; x <= n; x += x & -x) c[x] += v;
}
long long Ask(int x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += c[x];
  return ans;
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (depth[top[x]] < depth[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return depth[x] < depth[y] ? x : y;
}
int Goup(int x, int y) {
  while (top[x] != top[y]) {
    x = top[x];
    if (fa[x] == y) return x;
    x = fa[x];
  }
  return son[y];
}
long long dp[N], val[N];
long long Query(int x, int y) {
  long long ans = dp[son[x]];
  while (top[x] != top[y]) {
    ans += Ask(I[x]) - Ask(I[top[x]] - 1);
    ans -= dp[top[x]];
    x = fa[top[x]];
    ans += dp[son[x]];
  }
  ans += Ask(I[x]) - Ask(I[y] - 1);
  return ans;
}
void dfs3(int x) {
  dp[x] = 0;
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y != fa[x]) {
      dfs3(y);
      dp[x] += dp[y];
      if (y != son[x]) val[x] += dp[y];
    }
  }
  Add(I[x], val[x]);
  for (int cly = 0; cly < id[x].size(); cly++) {
    int i = id[x][cly];
    dp[x] = max(dp[x], Query(a[i].x, x) + Query(a[i].y, x) - val[x] -
                           dp[son[x]] + a[i].z);
  }
}
int main() {
  n = read();
  if (1) m = read();
  for (int i = 1; i <= n - 1; i++) {
    if (1) {
      int f = read();
      e[i + 1].push_back(f), e[f].push_back(i + 1);
    } else {
      int x = read(), y = read();
      e[x].push_back(y), e[y].push_back(x);
    }
  }
  dfs1(1, 0, 0);
  dfs2(1, 1);
  if (!1) m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    a[i].x = x, a[i].y = y, a[i].z = z;
    id[LCA(x, y)].push_back(i);
  }
  dfs3(1);
  cout << dp[1] << endl;
  return 0;
}
