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 edge {
  int u, v, cost;
};
vector<int> G[200005];
vector<edge> H[200005];
int root, n, m, t;
int parent[20][200005], depth[200005], l[200005], r[200005], bit[200005 + 1],
    dp[200005], s[200005];
int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(int i, int x) {
  while (i < 200005) {
    bit[i] += x;
    i += i & -i;
  }
}
void dfs(int v, int p, int d) {
  l[v] = ++t;
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0; i < G[v].size(); i++)
    if (G[v][i] != p) dfs(G[v][i], v, d + 1);
  r[v] = t;
}
void init(int V) {
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < 20; k++) {
    for (int v = 0; v < n; v++) {
      if (parent[k][v] < 0)
        parent[k + 1][v] = -1;
      else
        parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = 0; k < 20; k++) {
    if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
  }
  if (u == v) return u;
  for (int k = 20 - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
void solve(int v) {
  for (int i = 0; i < G[v].size(); i++) {
    solve(G[v][i]);
    s[v] += dp[G[v][i]];
  }
  dp[v] = s[v];
  for (int i = 0; i < H[v].size(); i++) {
    edge e = H[v][i];
    dp[v] = max(dp[v], sum(l[e.u]) + sum(l[e.v]) + s[v] + e.cost);
  }
  add(l[v], s[v] - dp[v]);
  add(r[v] + 1, dp[v] - s[v]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int x;
    scanf("%d", &x);
    G[x - 1].push_back(i);
  }
  init(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    H[lca(u, v)].push_back((edge){u, v, w});
  }
  memset(bit, 0, sizeof(bit));
  memset(dp, 0, sizeof(dp));
  memset(s, 0, sizeof(s));
  solve(0);
  printf("%d\n", dp[0]);
  return 0;
}