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 ST {
  long long val[800010];
  void pushdown(int root) {
    val[root << 1] += val[root];
    val[root << 1 | 1] += val[root];
    val[root] = 0;
    return;
  }
  void add(int root, int l, int r, int x, int y, long long z) {
    if (x <= l && r <= y) {
      val[root] += z;
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(root);
    if (x <= mid) add(root << 1, l, mid, x, y, z);
    if (y > mid) add(root << 1 | 1, mid + 1, r, x, y, z);
    return;
  }
  long long query(int root, int l, int r, int x) {
    if (l == r) return val[root];
    int mid = (l + r) >> 1;
    pushdown(root);
    if (x <= mid)
      return query(root << 1, l, mid, x);
    else
      return query(root << 1 | 1, mid + 1, r, x);
  }
} S, T;
int n, m;
int dfn[200010], to[200010], now;
long long f[200010], sum[200010];
vector<int> e[200010];
const int M = 20;
int fa[200010][20];
int dep[200010];
void init() {
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  return;
}
int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int need = dep[u] - dep[v], cur = 0;
  while (need) {
    if (need & 1) u = fa[u][cur];
    cur++;
    need >>= 1;
  }
  if (u == v) return u;
  for (int i = M - 1; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
struct Path {
  int u, v, c;
  Path(int uu = 0, int vv = 0, int cc = 0) {
    u = uu;
    v = vv;
    c = cc;
  }
};
vector<Path> vec[200010];
void dfs(int u) {
  dfn[u] = ++now;
  sum[u] = 0;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    dfs(v);
    sum[u] += f[v];
  }
  to[u] = now;
  f[u] = sum[u];
  for (int i = 0; i < vec[u].size(); i++) {
    int p = vec[u][i].u;
    int q = vec[u][i].v;
    int c = vec[u][i].c;
    long long val = sum[u] + c;
    val += S.query(1, 1, n, dfn[p]) - T.query(1, 1, n, dfn[p]);
    val += S.query(1, 1, n, dfn[q]) - T.query(1, 1, n, dfn[q]);
    f[u] = max(f[u], val);
  }
  S.add(1, 1, n, dfn[u], to[u], sum[u]);
  T.add(1, 1, n, dfn[u], to[u], f[u]);
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  dep[1] = 1;
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    e[p].push_back(i);
    fa[i][0] = p;
    dep[i] = dep[p] + 1;
  }
  init();
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    int lca = getlca(u, v);
    vec[lca].push_back(Path(u, v, c));
  }
  dfs(1);
  printf("%I64d\n", f[1]);
  return 0;
}