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 M = 400400;
int to[M], fi[M], la[M], tot, dep[M], fa[M], siz[M], son[M], sum[M], f[M],
    sf[M], top[M], n, m, x, y, z, ne[M];
struct node {
  int x, y, z;
  node(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
};
vector<node> g[M / 2];
void add(int x, int y) {
  to[++tot] = y;
  !fi[x] ? fi[x] = tot : ne[la[x]] = tot;
  la[x] = tot;
}
void dfs(int x, int par) {
  fa[x] = par;
  dep[x] = dep[par] + 1;
  siz[x] = 1;
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == par) continue;
    dfs(v, x);
    siz[x] += siz[v];
    if (siz[v] > siz[son[x]]) son[x] = v;
  }
}
void link(int x, int tp) {
  top[x] = tp;
  if (son[x]) link(son[x], tp);
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == fa[x] || v == son[x]) continue;
    link(v, v);
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] > dep[top[y]])
      x = fa[top[x]];
    else
      y = fa[top[y]];
  }
  return dep[x] > dep[y] ? y : x;
}
int calc(int x, int y) {
  int ans = 0;
  while (top[y] != top[x]) {
    ans += sum[top[x]] - sum[son[x]] - (sf[top[x]] - sf[son[x]]);
    x = fa[top[x]];
  }
  ans += sum[y] - sum[son[x]] - (sf[son[y]] - sf[son[x]]);
  return ans;
}
void solve(int x) {
  for (int i = fi[x]; i; i = ne[i]) {
    int v = to[i];
    if (v == fa[x]) continue;
    solve(v);
    sum[x] += f[v];
  }
  f[x] = sum[x];
  sum[x] += sum[son[x]];
  for (int i = 0; i < g[x].size(); i++) {
    f[x] = max(f[x], calc(g[x][i].x, x) + calc(g[x][i].y, x) - sum[x] +
                         sum[son[x]] + g[x][i].z);
  }
  sf[x] = f[x] + sf[son[x]];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    add(i, x);
    add(x, i);
  }
  dfs(1, 0);
  link(1, 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    g[lca(x, y)].push_back(node(x, y, z));
  }
  solve(1);
  printf("%d\n", f[1]);
  return 0;
}