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 MAXN = 200011;
vector<int> G[MAXN];
vector<int> P[MAXN];
int pu[MAXN], pv[MAXN], pw[MAXN];
int dp[MAXN], ind[MAXN], oud[MAXN], dep[MAXN];
int anc[MAXN][20];
int n, m, dfsclk;
namespace BIT1 {
long long f[MAXN];
int n;
void Init(int _n) {
  n = _n;
  memset(f, 0, sizeof(*f) * (n + 3));
}
void Modify(int x, int v) {
  for (; x <= n; x += x & (-x)) f[x] += v;
}
long long Query(int x) {
  long long res = 0;
  for (; x; x -= x & (-x)) res += f[x];
  return res;
}
}  // namespace BIT1
namespace BIT2 {
long long f[MAXN];
int n;
void Init(int _n) {
  n = _n;
  memset(f, 0, sizeof(*f) * (n + 3));
}
void Modify(int x, int v) {
  for (; x <= n; x += x & (-x)) f[x] += v;
}
long long Query(int x) {
  long long res = 0;
  for (; x; x -= x & (-x)) res += f[x];
  return res;
}
}  // namespace BIT2
void ModifyNode1(int x, int v) {
  BIT1::Modify(ind[x], v);
  BIT1::Modify(oud[x] + 1, -v);
}
void ModifyNode2(int x, int v) {
  BIT2::Modify(ind[x], v);
  BIT2::Modify(oud[x] + 1, -v);
}
long long QueryChain1(int x, int y, int lca) {
  return BIT1::Query(ind[x]) + BIT1::Query(ind[y]) - BIT1::Query(ind[lca]) -
         BIT1::Query(ind[anc[lca][0]]);
}
long long QueryChain2(int x, int y, int lca) {
  return BIT2::Query(ind[x]) + BIT2::Query(ind[y]) - BIT2::Query(ind[lca]) -
         BIT2::Query(ind[anc[lca][0]]);
}
inline void AddEdge(int x, int y) { G[x].push_back(y); }
void DFS(int x, int f) {
  ind[x] = ++dfsclk;
  dep[x] = dep[f] + 1;
  anc[x][0] = f;
  for (int i = 1; i < 19; ++i) {
    anc[x][i] = anc[anc[x][i - 1]][i - 1];
  }
  for (int i = 0; i < (int)G[x].size(); ++i) {
    int to = G[x][i];
    if (to != f) {
      DFS(to, x);
    }
  }
  oud[x] = dfsclk;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int sub = dep[x] - dep[y];
  for (int i = 0; i < 19; ++i) {
    if (sub & (1 << i)) x = anc[x][i];
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; --i) {
    if (anc[x][i] != anc[y][i]) {
      x = anc[x][i];
      y = anc[y][i];
    }
  }
  return anc[x][0];
}
int Jump(int x, int d) {
  for (int i = 0; i < 19; ++i) {
    if (d & (1 << i)) x = anc[x][i];
  }
  return x;
}
void Solve(int x, int f) {
  dp[x] = 0;
  int tot = 0;
  for (int i = 0; i < (int)G[x].size(); ++i) {
    int to = G[x][i];
    if (to != f) {
      Solve(to, x);
      tot += dp[to];
    }
  }
  dp[x] = tot;
  for (int i = 0; i < (int)P[x].size(); ++i) {
    int id = P[x][i];
    int u = pu[id], v = pv[id], w = pw[id];
    long long s = QueryChain2(u, v, x) - QueryChain1(u, v, x);
    dp[x] = max(dp[x], (int)(s + w));
  }
  ModifyNode1(x, dp[x]);
  if (f) ModifyNode2(f, dp[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2, x; i <= n; ++i) {
    scanf("%d", &x);
    AddEdge(x, i);
    AddEdge(i, x);
  }
  DFS(1, 0);
  for (int i = 1, x, y, w; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &w);
    pu[i] = x;
    pv[i] = y;
    pw[i] = w;
    P[LCA(x, y)].push_back(i);
  }
  BIT1::Init(n + 1);
  BIT2::Init(n + 1);
  Solve(1, 0);
  printf("%d\n", dp[1]);
  return 0;
}