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;
const int Maxn = 3e5 + 10;
int a[Maxn], dep[Maxn], head[Maxn], cnt, g[2 * Maxn], nxt[2 * Maxn];
int dfn[Maxn], sum[Maxn], n, m, re[Maxn], f[Maxn][25], dp[Maxn];
vector<int> dui[Maxn];
struct Note {
  int x, y, v;
} que[Maxn];
struct Tree {
  int t[4 * Maxn], tag[4 * Maxn];
  inline void build(int x, int l, int r) {
    if (l == r) {
      t[x] = a[re[l]];
      return;
    }
    int Mid = (l + r) >> 1;
    build(x * 2, l, Mid);
    build(x * 2 + 1, Mid + 1, r);
    t[x] = t[x * 2] + t[x * 2 + 1];
  }
  inline int query(int x, int l, int r, int L, int R) {
    if (l >= L && r <= R) return t[x];
    if (l > R || r < L) return 0;
    if (l > r) return 0;
    int Mid = (l + r) >> 1;
    int res = 0;
    pushdown(x, l, r);
    if (l <= Mid) res += query(x * 2, l, Mid, L, R);
    if (r > Mid) res += query(x * 2 + 1, Mid + 1, r, L, R);
    return res;
  }
  void pushdown(int x, int l, int r) {
    int Mid = (l + r) >> 1, lz = x * 2, rz = x * 2 + 1, v = tag[x];
    if (tag[x]) {
      tag[x] = 0;
      t[lz] += v * (Mid - l + 1);
      tag[lz] += v;
      tag[rz] += v;
      t[rz] += v * (r - Mid);
    }
  }
  void update(int x, int l, int r, int L, int R, int D) {
    if (l > r) return;
    if (l >= L && r <= R) {
      t[x] += D * (r - l + 1);
      tag[x] += D;
      return;
    }
    int Mid = (l + r) >> 1;
    pushdown(x, l, r);
    if (L <= Mid) update(x * 2, l, Mid, L, R, D);
    if (R > Mid) update(x * 2 + 1, Mid + 1, r, L, R, D);
    t[x] = t[x * 2] + t[x * 2 + 1];
  }
} t1, t2;
inline void addedge(int x, int y) {
  cnt++;
  nxt[cnt] = head[x];
  g[cnt] = y;
  head[x] = cnt;
}
inline void dfs(int x, int fa) {
  f[x][0] = fa;
  sum[x] = 1;
  dfn[x] = ++cnt;
  re[cnt] = x;
  dep[x] = dep[fa] + 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (g[i] != fa) {
      dfs(g[i], x);
      sum[x] += sum[g[i]];
    }
  }
}
void dfs2(int x, int fa) {
  int res = 0;
  for (int i = head[x]; i; i = nxt[i]) {
    if (g[i] != fa) {
      dfs2(g[i], x);
      res += dp[g[i]];
    }
  }
  t1.update(1, 1, n, dfn[x], dfn[x] + sum[x] - 1, res);
  int ssum = dui[x].size();
  dp[x] = res;
  for (int i = 0; i < ssum; i++) {
    int xx = que[dui[x][i]].x, yy = que[dui[x][i]].y;
    int value = 0;
    value += t1.query(1, 1, n, dfn[xx], dfn[xx]);
    value += t1.query(1, 1, n, dfn[yy], dfn[yy]);
    value -= res;
    value -= t2.query(1, 1, n, dfn[xx], dfn[xx]);
    value -= t2.query(1, 1, n, dfn[yy], dfn[yy]);
    if (value + que[dui[x][i]].v > dp[x]) dp[x] = value + que[dui[x][i]].v;
  }
  t2.update(1, 1, n, dfn[x], dfn[x] + sum[x] - 1, dp[x]);
}
void init() {
  for (int i = 1; i <= 22; i++)
    for (int j = 1; j <= n; j++) f[j][i] = f[f[j][i - 1]][i - 1];
}
int lca(int x, int y) {
  long long res = 0;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 22; i >= 0; i--) {
    if (dep[f[x][i]] >= dep[y]) {
      x = f[x][i];
    }
  }
  for (int i = 22; i >= 0; i--) {
    if (f[x][i] != f[y][i]) {
      x = f[x][i];
      y = f[y][i];
    }
  }
  if (x != y)
    return f[x][0];
  else
    return x;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    addedge(i, x);
    addedge(x, i);
  }
  cnt = 0;
  dfs(1, 0);
  init();
  t1.build(1, 1, n);
  t2.build(1, 1, n);
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    que[i].x = x, que[i].y = y, que[i].v = z;
    int LCA = lca(x, y);
    dui[LCA].push_back(i);
  }
  dfs2(1, 0);
  printf("%d", dp[1]);
  return 0;
}