Problem: Masha is fond of cacti. When she was a little girl, she decided to plant a tree. Now Masha wants to make a nice cactus out of her tree.

Recall that tree is a connected undirected graph that has no cycles. Cactus is a connected undirected graph such that each vertex belongs to at most one cycle.

Masha has some additional edges that she can add to a tree. For each edge she knows which vertices it would connect and the beauty of this edge. Masha can add some of these edges to the graph if the resulting graph is a cactus. Beauty of the resulting cactus is sum of beauties of all added edges. 

Help Masha find out what maximum beauty of the resulting cactus she can achieve.

Input

The first line of the input data contains two integers n and m — the number of vertices in a tree, and the number of additional edges available (3 ≤ n ≤ 2·105; 0 ≤ m ≤ 2·105).

Let us describe Masha's tree. It has a root at vertex 1. The second line contains n - 1 integers: p2, p3, ..., pn, here pi — is the parent of a vertex i — the first vertex on a path from the vertex i to the root of the tree (1 ≤ pi < i).

The following m lines contain three integers ui, vi and ci — pairs of vertices to be connected by the additional edges that Masha can add to the tree and beauty of edge (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ ci ≤ 104).

It is guaranteed that no additional edge coincides with the edge of the tree.

Output

Output one integer — the maximum beauty of a cactus Masha can achieve.

Example

Input

7 3
1 1 2 2 3 3
4 5 1
6 7 1
2 3 1


Output

2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct FastIO {
  static const int S = 1310720;
  int wpos;
  char wbuf[S];
  FastIO() : wpos(0) {}
  inline int xchar() {
    static char buf[S];
    static int len = 0, pos = 0;
    if (pos == len) pos = 0, len = fread(buf, 1, S, stdin);
    if (pos == len) return -1;
    return buf[pos++];
  }
  inline int xuint() {
    int c = xchar(), x = 0;
    while (c <= 32) c = xchar();
    for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
    return x;
  }
  inline int xint(int& in) {
    int s = 1, c = xchar(), x = 0;
    while (c <= 32) {
      c = xchar();
      if (c == -1) {
        return 0;
      }
    }
    if (c == '-') s = -1, c = xchar();
    for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
    int res = x * s;
    in = res;
    return 1;
  }
  inline void xstring(char* s) {
    int c = xchar();
    while (c <= 32) c = xchar();
    for (; c > 32; c = xchar()) *s++ = c;
    *s = 0;
  }
  inline void wchar(int x) {
    if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
    wbuf[wpos++] = x;
  }
  inline void wint(int x) {
    if (x < 0) wchar('-'), x = -x;
    char s[24];
    int n = 0;
    while (x || !n) s[n++] = '0' + x % 10, x /= 10;
    while (n--) wchar(s[n]);
  }
  inline void wstring(const char* s) {
    while (*s) wchar(*s++);
  }
  ~FastIO() {
    if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
  }
} io;
int n, m, tot;
struct E {
  int a;
  int nxt;
};
struct TR {
  int x, y, z;
};
int g[100013 * 2];
E e[100013 * 2 << 1];
TR q[100013 * 2];
int ace[100013 * 2][19];
void addE(int x, int y) {
  ++tot;
  e[tot].a = y;
  e[tot].nxt = g[x];
  g[x] = tot;
}
int siz[100013 * 2], top[100013 * 2], fa[100013 * 2], son[100013 * 2],
    deep[100013 * 2], tid[100013 * 2];
void dfs1(int v, int p, int d) {
  siz[v] = 1;
  deep[v] = d;
  fa[v] = p;
  son[v] = -1;
  for (int i = g[v]; i != -1; i = e[i].nxt) {
    int w = e[i].a;
    if (w == p) {
      continue;
    }
    dfs1(w, v, d + 1);
    siz[v] += siz[w];
    if (son[v] == -1 || siz[w] > siz[son[v]]) {
      son[v] = w;
    }
  }
  return;
}
long long tr[1000013 * 2];
void ins(int d, int l, int r, int x, int c) {
  if (l > r || x < l || x > r) return;
  if (l == r) {
    tr[d] = c;
    return;
  }
  int o = l + r >> 1, ll = d << 1, rr = ll + 1;
  if (x <= o)
    ins(ll, l, o, x, c);
  else
    ins(rr, o + 1, r, x, c);
  tr[d] = tr[ll] + tr[rr];
}
long long query(int d, int l, int r, int x, int y) {
  if (l > r || x > y || x < l || y > r) return 0;
  if (l == x && y == r) {
    return tr[d];
  }
  int o = l + r >> 1, ll = d << 1, rr = ll + 1;
  long long res = 0;
  if (y <= o)
    res = query(ll, l, o, x, y);
  else if (x > o)
    res = query(rr, o + 1, r, x, y);
  else
    res = query(ll, l, o, x, o) + query(rr, o + 1, r, o + 1, y);
  return res;
}
std::vector<int> v[100013 * 2];
void dfs2(int v, int tp, int& k) {
  top[v] = tp;
  tid[v] = ++k;
  if (son[v] == -1) {
    return;
  }
  dfs2(son[v], tp, k);
  for (int i = g[v]; i != -1; i = e[i].nxt) {
    int w = e[i].a;
    if (w == fa[v] || w == son[v]) {
      continue;
    }
    dfs2(w, w, k);
  }
}
long long ans[100013 * 2], sans[100013 * 2];
long long fts(int u, int v) {
  long long ans = 0;
  while (top[u] != top[v]) {
    if (deep[top[u]] > deep[top[v]]) {
      ans += query(1, 1, n, tid[top[u]], tid[u]);
      u = fa[top[u]];
    } else {
      ans += query(1, 1, n, tid[top[v]], tid[v]);
      v = fa[top[v]];
    }
  }
  if (deep[u] < deep[v]) {
    ans += query(1, 1, n, tid[u], tid[v]);
  } else {
    ans += query(1, 1, n, tid[v], tid[u]);
  }
  return ans;
}
void dfs(int x) {
  sans[x] = 0;
  for (int p = g[x]; p != -1; p = e[p].nxt) {
    int y = e[p].a;
    if (y != fa[x]) {
      dfs(y);
      sans[x] += ans[y];
    }
  }
  ans[x] = sans[x];
  for (int i = 0; i < v[x].size(); ++i) {
    TR k = q[v[x][i]];
    long long tmp;
    tmp = fts(x, k.x) + fts(x, k.y) + sans[x] + k.z;
    ans[x] = max(ans[x], tmp);
  }
  ins(1, 1, n, tid[x], sans[x] - ans[x]);
}
int acen(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  int j = 18;
  while (deep[x] != deep[y]) {
    if (ace[x][j] != 0) {
      if (deep[ace[x][j]] >= deep[y]) x = ace[x][j];
    }
    --j;
  }
  if (x == y) return x;
  j = 18;
  int l = deep[x], r = 0, ac = 1;
  while (r + 1 < l) {
    int a = ace[x][j];
    int b = ace[y][j];
    if (a == b) {
      if (a != 0 && deep[a] > r) r = deep[a], ac = a;
    } else {
      x = ace[x][j];
      y = ace[y][j];
      l = deep[x];
    }
    --j;
  }
  return ac;
}
int main() {
  int T = 1;
  for (int ci = 1; ci <= T; ++ci) {
    scanf("%d%d", &n, &m);
    tot = -1;
    memset(g, -1, sizeof(g));
    for (int i = 2; i <= n; ++i) {
      int x;
      scanf("%d", &x);
      addE(i, x);
      addE(x, i);
    }
    dfs1(1, 0, 0);
    int k = 0;
    dfs2(1, 1, k);
    for (int i = 0; i < 19; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (i == 0)
          ace[j][i] = fa[j];
        else {
          int t = ace[j][i - 1];
          if (t == 0)
            ace[j][i] = 0;
          else
            ace[j][i] = ace[t][i - 1];
        }
      }
    }
    for (int i = 1; i <= n; ++i) v[i].clear();
    for (int i = 0; i < m; ++i) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      q[i].x = x;
      q[i].y = y;
      q[i].z = z;
      int aa = acen(x, y);
      v[aa].push_back(i);
    }
    memset(tr, 0, sizeof(tr));
    dfs(1);
    cout << ans[1] << endl;
  }
  return 0;
}