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 point {
  int a, b, c;
};
vector<int> E[201000];
vector<point> G[201000];
int n, m, par[201000][20], Dep[201000], Num[201000], Ed[201000], cnt, D[201000],
    D2[201000];
long long BIT[201000][2];
void DFS(int a, int dep) {
  int i;
  Num[a] = ++cnt;
  Dep[a] = dep;
  for (i = 0; i < E[a].size(); i++) DFS(E[a][i], dep + 1);
  Ed[a] = cnt;
}
int Up(int a, int d) {
  int i = 0;
  while (d) {
    if (d & 1) a = par[a][i];
    d >>= 1;
    i++;
  }
  return a;
}
int LCA(int a, int b) {
  if (Dep[a] < Dep[b]) return LCA(b, a);
  a = Up(a, Dep[a] - Dep[b]);
  for (int i = 17; i >= 0; i--)
    if (par[a][i] != par[b][i]) a = par[a][i], b = par[b][i];
  if (a != b) a = par[a][0];
  return a;
}
void Ins(int a, int b, int ck) {
  while (a <= n) {
    BIT[a][ck] += b;
    a += (a & -a);
  }
}
long long Sum(int a, int ck) {
  long long r = 0;
  while (a) {
    r += BIT[a][ck];
    a -= (a & -a);
  }
  return r;
}
void Make(int a, int x, int y, int c) {
  int t = D2[a] - Sum(Num[y], 0) + Sum(Num[y], 1) - Sum(Num[x], 0) +
          Sum(Num[x], 1) + c;
  D[a] = max(D[a], t);
}
void Do(int a) {
  int i;
  for (i = 0; i < E[a].size(); i++) {
    Do(E[a][i]);
    D2[a] += D[E[a][i]];
  }
  D[a] = D2[a];
  for (i = 0; i < G[a].size(); i++) {
    Make(a, G[a][i].a, G[a][i].b, G[a][i].c);
  }
  Ins(Num[a], D[a], 0);
  Ins(Ed[a] + 1, -D[a], 0);
  Ins(Num[a], D2[a], 1);
  Ins(Ed[a] + 1, -D2[a], 1);
}
int main() {
  int i, j, a, b, c;
  scanf("%d%d", &n, &m);
  for (i = 2; i <= n; i++) {
    scanf("%d", &par[i][0]);
    E[par[i][0]].push_back(i);
  }
  for (i = 0; i < 17; i++)
    for (j = 1; j <= n; j++) par[j][i + 1] = par[par[j][i]][i];
  DFS(1, 0);
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G[LCA(a, b)].push_back({a, b, c});
  }
  Do(1);
  printf("%d\n", D[1]);
}