#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" PRId64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f\n", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <class T>
inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
struct BIT {
  int n;
  vector<T> dat;
  void init(int _n) {
    n = _n;
    dat.clear();
    dat.resize(n + 1);
  }
  template <bool ask_range>
  void init(int _n, T a[]) {
    init(_n);
    for (int i = 1; i <= n; i++) {
      dat[i] += ask_range ? a[i] : a[i] - a[i - 1];
      int j = i + (i & -i);
      if (j <= n) dat[j] += dat[i];
    }
  }
  void add(int x, T v) {
    for (int i = x; i <= n; i += i & -i) dat[i] += v;
  }
  T ask(int x) {
    T s = T();
    for (int i = x; i; i -= i & -i) s += dat[i];
    return s;
  }
  void add(int l, int r, T v) {
    add(l, v);
    if (r + 1 <= n) add(r + 1, -v);
  }
  T ask(int l, int r) { return ask(r) - ask(l - 1); }
};
constexpr int lg2(int x) { return 31 - __builtin_clz(x); }
const int N = 2e5 + 10;
const int M = 2e5 + 10;
const int LGN = lg2(N) + 1;
struct Q {
  int a, b, c;
} q[M];
int n, m;
vector<int> e[N];
void input() {
  R(n, m);
  for (int i = (2); i <= int(n); i++) {
    int x;
    R(x);
    e[x].push_back(i);
  }
  for (int i = 0; i < int(m); i++) R(q[i].a, q[i].b, q[i].c);
}
int dep[N], fa[LGN][N], dt[N], ot[N], ts;
void dfs(int p, int f, int lv) {
  dep[p] = lv;
  fa[0][p] = f;
  dt[p] = ++ts;
  for (int i : e[p])
    if (i != f) dfs(i, p, lv + 1);
  ot[p] = ts;
}
int lgn;
void lca_build() {
  for (int i = 0; i < lgn; i++) {
    for (int j = 1; j <= n; j++) {
      fa[i + 1][j] = fa[i][fa[i][j]];
    }
  }
}
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  int d = dep[b] - dep[a];
  int l = lg2(dep[b]);
  for (int i = 0; i <= l; i++) {
    if ((d >> i) & 1) b = fa[i][b];
  }
  if (a == b) return a;
  for (int i = lg2(dep[a]); i >= 0; i--) {
    if (fa[i][a] != fa[i][b]) {
      a = fa[i][a];
      b = fa[i][b];
    }
  }
  return fa[0][a];
}
vector<int> vq[N];
void build() {
  dfs(1, 0, 1);
  lgn = lg2(n);
  lca_build();
  for (int i = 0; i < int(m); i++) {
    int p = lca(q[i].a, q[i].b);
    vq[p].push_back(i);
  }
}
int64_t dp[N];
BIT<int64_t> b1, b2;
int64_t shik(int a, int b, int c) {
  int d = fa[0][c];
  int64_t s = 0;
  int64_t sa1 = b1.ask(dt[a]);
  int64_t sb1 = b1.ask(dt[b]);
  int64_t sc1 = b1.ask(dt[c]);
  int64_t sa2 = b2.ask(dt[a]);
  int64_t sb2 = b2.ask(dt[b]);
  int64_t sc2 = b2.ask(dt[c]);
  int64_t sd2 = b2.ask(dt[d]);
  s += sa2 + sb2 - sc2 - sd2;
  s -= sa1 + sb1 - 2 * sc1;
  return s;
}
void go(int p) {
  for (int i : e[p]) go(i);
  int64_t mx = 0;
  {
    int64_t s = 0;
    for (int i : e[p]) s += dp[i];
    chkmax(mx, s);
  }
  for (int i : vq[p]) {
    int64_t now = shik(q[i].a, q[i].b, p) + q[i].c;
    chkmax(mx, now);
  }
  b1.add(dt[p], ot[p], mx);
  int f = fa[0][p];
  if (f != 0) b2.add(dt[f], ot[f], mx);
  dp[p] = mx;
}
void solve() {
  b1.init(n);
  b2.init(n);
  go(1);
  W(dp[1]);
}
int main() {
  input();
  build();
  solve();
  return 0;
}
