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>
int max(int a, int b) { return a > b ? a : b; }
int oo[1 + 200000 - 1 + 200000], ox[1 + 200000 - 1 + 200000];
int link(int o, int x) {
  static int _ = 1;
  oo[_] = o, ox[_] = x;
  return _++;
}
int ae[200000], ae_[200000], pp[200000], qq[200000], dd[200000], sz[200000],
    ta[200000], tb[200000], dp[200000], n;
int ii[200000], jj[200000], ww[200000];
void dfs1(int i, int d) {
  static int time = 0;
  int o, s;
  dd[i] = d;
  ta[i] = time++;
  s = 1;
  for (o = ae[i]; o; o = oo[o]) {
    int j = ox[o];
    dfs1(j, d + 1);
    s += sz[j];
  }
  sz[i] = s;
  tb[i] = time;
}
void dfs2(int i, int q) {
  int o, j_;
  qq[i] = q;
  j_ = -1;
  for (o = ae[i]; o; o = oo[o]) {
    int j = ox[o];
    if (j_ == -1 || sz[j_] < sz[j]) j_ = j;
  }
  for (o = ae[i]; o; o = oo[o]) {
    int j = ox[o];
    dfs2(j, j == j_ ? q : j);
  }
}
int lca(int i, int j) {
  while (qq[i] != qq[j])
    if (dd[qq[i]] > dd[qq[j]])
      i = pp[qq[i]];
    else
      j = pp[qq[j]];
  return dd[i] < dd[j] ? i : j;
}
int ft[200000];
void update(int i, int x) {
  while (i < n) {
    ft[i] += x;
    i |= i + 1;
  }
}
void update_(int l, int r, int x) { update(l, x), update(r, -x); }
int query(int i) {
  int x = 0;
  while (i >= 0) {
    x += ft[i];
    i &= i + 1, i--;
  }
  return x;
}
void dfs3(int i) {
  int o, sum, p;
  sum = 0;
  for (o = ae[i]; o; o = oo[o]) {
    int j = ox[o];
    dfs3(j);
    sum += dp[j];
  }
  p = sum;
  for (o = ae_[i]; o; o = oo[o]) {
    int h = ox[o];
    p = max(p, sum + query(ta[ii[h]]) + query(ta[jj[h]]) + ww[h]);
  }
  dp[i] = p;
  update_(ta[i], ta[i] + 1, sum - p);
  for (o = ae[i]; o; o = oo[o]) {
    int j = ox[o];
    update_(ta[j], tb[j], (sum - dp[j]) - (dp[i] - dp[j]));
  }
}
int main() {
  int m, h, i, j;
  scanf("%d%d", &n, &m);
  for (j = 1; j < n; j++) {
    scanf("%d", &i), i--;
    ae[i] = link(ae[i], j);
    pp[j] = i;
  }
  dfs1(0, 0);
  dfs2(0, 0);
  for (h = 0; h < m; h++) {
    int a;
    scanf("%d%d%d", &ii[h], &jj[h], &ww[h]), ii[h]--, jj[h]--;
    a = lca(ii[h], jj[h]);
    ae_[a] = link(ae_[a], h);
  }
  dfs3(0);
  printf("%d\n", dp[0]);
  return 0;
}