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;
int read() {
  char x = getchar();
  int ans = 0, flag = 1;
  while (!isdigit(x))
    if (x == '-')
      flag = -1, x = getchar();
    else
      x = getchar();
  while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar();
  return ans * flag;
}
int pnt[400005], nxt[400005], head[200005], id[200005], top[200005],
    siz[200005];
int E, fa[200005], son[200005], dep[200005], cnt, n, m, dp[200005], g[200005];
vector<int> vu[200005], vv[200005], vw[200005];
void add_edge(int u, int v) {
  pnt[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
}
void dfs1(int u, int pre) {
  fa[u] = pre;
  dep[u] = dep[pre] + 1;
  siz[u] = 1;
  int maxn = -1;
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = pnt[i];
    if (v == pre) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    if (siz[v] > maxn) son[u] = v, maxn = siz[v];
  }
}
void dfs2(int u, int pre) {
  top[u] = pre;
  id[u] = ++cnt;
  if (!son[u]) return;
  dfs2(son[u], pre);
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = pnt[i];
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  if (dep[x] > dep[y]) swap(x, y);
  return x;
}
int ls(int p) { return p << 1; }
int rs(int p) { return p << 1 | 1; }
struct segment_tree {
  int tree[800005], lazy_tag[800005];
  void pushup(int p) { tree[p] = tree[ls(p)] + tree[rs(p)]; }
  void update(int l, int r, int ll, int rr, int k, int p) {
    if (ll <= l && r <= rr) {
      tree[p] += k;
      return;
    }
    int mid = (l + r) >> 1;
    if (ll <= mid) update(l, mid, ll, rr, k, ls(p));
    if (rr > mid) update(mid + 1, r, ll, rr, k, rs(p));
    pushup(p);
  }
  int query(int l, int r, int ll, int rr, int p) {
    if (ll <= l && r <= rr) {
      return tree[p];
    }
    int mid = (l + r) >> 1, tmp = 0;
    if (ll <= mid) tmp += query(l, mid, ll, rr, ls(p));
    if (rr > mid) tmp += query(mid + 1, r, ll, rr, rs(p));
    return tmp;
  }
} tree1, tree2;
int qu(int x, int y) {
  int tmp1 = 0, tmp2 = 0;
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    tmp1 += tree1.query(1, n, id[top[x]], id[x], 1);
    tmp2 += tree2.query(1, n, id[top[x]], id[x], 1);
    x = fa[top[x]];
  }
  if (dep[x] > dep[y]) swap(x, y);
  tmp1 += tree1.query(1, n, id[x], id[y], 1);
  tmp2 += tree2.query(1, n, id[x], id[y], 1);
  return tmp2 - tmp1;
}
void dfs(int u, int pre) {
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = pnt[i];
    if (v == pre) continue;
    dfs(v, u);
    dp[u] += dp[v];
    g[u] += dp[v];
  }
  tree2.update(1, n, id[u], id[u], g[u], 1);
  for (int i = 0; i < vv[u].size(); i++) {
    int uu = vu[u][i], v = vv[u][i], w = vw[u][i];
    dp[u] = max(dp[u], w + qu(uu, v));
  }
  tree1.update(1, n, id[u], id[u], dp[u], 1);
}
signed main() {
  memset(head, -1, sizeof(head));
  n = read(), m = read();
  for (int v = 2; v <= n; v++) {
    int u = read();
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read(), w = read();
    int LCA = lca(u, v);
    vu[LCA].push_back(u);
    vv[LCA].push_back(v);
    vw[LCA].push_back(w);
  }
  dfs(1, 0);
  cout << dp[1] << endl;
  return 0;
}