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;
long long i, j, k, l, s, n, m, F[200005], st[200005], tot, fa[200005],
    f[200005][2], si[200005], dis[200005], T[200005], G[200005];
struct node {
  long long lca, x, y, v;
} a[200005];
struct NODE {
  long long last[200005], next[200005], to[200005];
  inline void add(long long x, long long y) {
    next[++tot] = last[x];
    last[x] = tot;
    to[tot] = y;
  }
} A, B;
struct Node {
  long long t[200005];
  inline void insert(long long x, long long y) {
    for (; x <= n; x += x & (-x)) t[x] += y;
  }
  inline long long ask(long long x) {
    long long s = 0;
    for (; x; x -= x & (-x)) s += t[x];
    return s;
  }
} C, D;
inline void dfs(long long o, long long p) {
  if (!p) p = o;
  F[o] = p;
  st[o] = ++tot;
  long long gt = 0, gtw = 0;
  for (long long i = A.last[o]; i; i = A.next[i])
    if (si[A.to[i]] > gt) gt = si[A.to[i]], gtw = A.to[i];
  if (gtw) dfs(gtw, p);
  for (long long i = A.last[o]; i; i = A.next[i])
    if (A.to[i] != gtw) dfs(A.to[i], 0);
}
inline long long getlca(long long x, long long y) {
  while (F[x] != F[y]) {
    if (dis[F[x]] > dis[F[y]])
      x = fa[F[x]];
    else
      y = fa[F[y]];
  }
  if (dis[x] > dis[y]) return y;
  return x;
}
inline long long ask(long long o, long long x, long long y) {
  long long ans = C.ask(st[o]) - C.ask(st[o] - 1);
  while (F[x] != F[o]) {
    ans += C.ask(st[x]) - C.ask(st[F[x]] - 1);
    ans += D.ask(st[x]) - D.ask(st[F[x]] - 1);
    x = fa[F[x]];
  }
  ans += C.ask(st[x]) - C.ask(st[o]);
  ans += D.ask(st[x]) - D.ask(st[o]);
  while (F[y] != F[o]) {
    ans += C.ask(st[y]) - C.ask(st[F[y]] - 1);
    ans += D.ask(st[y]) - D.ask(st[F[y]] - 1);
    y = fa[F[y]];
  }
  ans += C.ask(st[y]) - C.ask(st[o]);
  ans += D.ask(st[y]) - D.ask(st[o]);
  return ans;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  for (i = 2; i <= n; i++) scanf("%I64d", &fa[i]), A.add(fa[i], i);
  for (i = n; i; i--) si[i]++, si[fa[i]] += si[i];
  for (i = 1; i <= n; i++) dis[i] = dis[fa[i]] + 1;
  tot = 0;
  dfs(1, 0);
  tot = 0;
  for (i = 1; i <= m; i++) {
    scanf("%I64d%I64d%I64d", &a[i].x, &a[i].y, &a[i].v);
    a[i].lca = getlca(a[i].x, a[i].y);
    B.add(a[i].lca, i);
  }
  for (i = n; i; i--) {
    C.insert(st[i], G[i]);
    for (j = A.last[i]; j; j = A.next[j]) f[i][0] += T[A.to[j]];
    for (j = B.last[i]; j; j = B.next[j])
      f[i][1] = max(f[i][1], ask(i, a[B.to[j]].x, a[B.to[j]].y) + a[B.to[j]].v);
    T[i] = max(f[i][0], f[i][1]);
    G[fa[i]] += T[i];
    D.insert(st[i], -T[i]);
  }
  printf("%I64d\n", T[1]);
}