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 N = 200010;
int n, m, x, y, k, ancestor[N], fa[N], fi[N], u[N], v[N], sum[N], dp[N],
    ne[N << 1], b[N << 1], money[N], sz[N], top[N], son[N], contribution[N];
vector<pair<int, int> > g[N];
vector<int> w[N];
inline void add(int x, int y) {
  b[++k] = y;
  ne[k] = fi[x];
  fi[x] = k;
}
inline int ask(int x) {
  return x == ancestor[x] ? x : ancestor[x] = ask(ancestor[x]);
}
inline int ask2(int x) { return x == top[x] ? x : top[x] = ask2(top[x]); }
inline void dfs(int x) {
  sz[x] = 1;
  for (int j = fi[x]; j; j = ne[j]) {
    fa[b[j]] = x;
    dfs(b[j]);
    ancestor[b[j]] = x;
    sz[x] += sz[b[j]];
    if (sz[b[j]] > sz[son[x]]) son[x] = b[j];
  }
  top[son[x]] = x;
  for (vector<pair<int, int> >::iterator it = g[x].begin(); it != g[x].end();
       it++)
    if (it->second == 1 || fa[it->second])
      w[ask(it->second)].push_back(it->first);
}
int calc(int i, int x) {
  int y = u[i], z = v[i], res = sum[y] + sum[z];
  while (top[y] != top[x])
    res +=
        contribution[top[y]] - contribution[y] + sum[fa[top[y]]] - dp[top[y]],
        y = fa[top[y]];
  res += contribution[x] - contribution[y];
  while (top[z] != top[x])
    res +=
        contribution[top[z]] - contribution[z] + sum[fa[top[z]]] - dp[top[z]],
        z = fa[top[z]];
  res += contribution[x] - contribution[z];
  return res - sum[x] + money[i];
}
void getans(int x) {
  for (int j = fi[x]; j; j = ne[j]) {
    getans(b[j]);
    sum[x] += dp[b[j]];
  }
  dp[x] = sum[x];
  contribution[x] = contribution[son[x]] + sum[x] - dp[son[x]];
  for (vector<int>::iterator it = w[x].begin(); it != w[x].end(); it++)
    dp[x] = max(dp[x], calc(*it, x));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    add(x, i);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u[i], &v[i], &money[i]);
    g[u[i]].push_back(make_pair(i, v[i]));
    g[v[i]].push_back(make_pair(i, u[i]));
  }
  for (int i = 1; i <= n; i++) ancestor[i] = top[i] = i;
  dfs(1);
  for (int i = 1; i <= n; i++) ask2(i);
  for (int i = 1; i <= n; i++)
    w[i].erase(unique(w[i].begin(), w[i].end()), w[i].end());
  getans(1);
  printf("%d", dp[1]);
}