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 mod = 998244353;
const int MAXN = 200005;
struct path {
  int cost, s, e;
};
int n, m;
vector<int> graph[MAXN];
vector<path> paths[MAXN];
int par[MAXN][18], dep[MAXN];
int dfn[MAXN], sz[MAXN], p0, tra[MAXN];
int comp[MAXN], cnum[MAXN], chead[MAXN], csize[MAXN], piv;
int son[MAXN];
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  int diff = dep[y] - dep[x];
  for (int i = 0; i < 18; i++) {
    if ((diff >> i) & 1) y = par[y][i];
  }
  for (int i = 17; i >= 0; i--) {
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  }
  if (x == y) return x;
  return par[x][0];
}
void dfs(int pos, int pa) {
  dfn[pos] = ++p0;
  tra[dfn[pos]] = pos;
  par[pos][0] = pa;
  for (int i = 1; i < 18; i++) {
    par[pos][i] = par[par[pos][i - 1]][i - 1];
  }
  for (auto &x : graph[pos]) {
    if (x == pa) continue;
    dep[x] = dep[pos] + 1;
    dfs(x, pos);
    sz[pos] += sz[x];
  }
  sz[pos]++;
}
void hld(int pos) {
  comp[pos] = piv;
  cnum[pos] = ++csize[piv];
  int pmax = -1, vmax = -1;
  for (int i = 0; i < graph[pos].size(); i++) {
    if (graph[pos][i] == par[pos][0]) continue;
    if (vmax < sz[graph[pos][i]]) {
      vmax = sz[graph[pos][i]];
      pmax = i;
    }
  }
  if (pmax == -1) return;
  son[pos] = graph[pos][pmax];
  hld(graph[pos][pmax]);
  for (int i = 0; i < graph[pos].size(); i++) {
    if (graph[pos][i] == par[pos][0] || i == pmax) continue;
    piv++;
    chead[piv] = graph[pos][i];
    hld(graph[pos][i]);
  }
}
int dp[MAXN], sum[MAXN];
int mark[MAXN];
vector<int> psum[MAXN];
int getsum(int num, int s, int e) {
  if (s > e) return 0;
  return psum[num][s] - psum[num][e + 1];
}
int f(int x, int y, int l) {
  int ret = 0;
  while (comp[x] != comp[l]) {
    ret += getsum(comp[x], 1, cnum[x]);
    x = par[chead[comp[x]]][0];
  }
  ret += getsum(comp[l], cnum[l] + 1, cnum[x]);
  while (comp[y] != comp[l]) {
    ret += getsum(comp[y], 1, cnum[y]);
    y = par[chead[comp[y]]][0];
  }
  ret += getsum(comp[l], cnum[l] + 1, cnum[y]);
  ret += sum[l];
  return ret;
}
void solve() {
  for (int i = n; i; i--) {
    int pos = tra[i];
    for (auto &j : graph[pos]) {
      if (j == par[pos][0]) continue;
      sum[pos] += dp[j];
    }
    int ret = sum[pos];
    for (auto &j : paths[pos]) {
      ret = max(ret, f(j.s, j.e, pos) + j.cost);
    }
    dp[pos] = ret;
    ret = sum[pos] - dp[pos];
    psum[comp[pos]][cnum[pos]] = psum[comp[pos]][cnum[pos] + 1] + ret;
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    graph[p].push_back(i);
    graph[i].push_back(p);
  }
  dfs(1, 0);
  for (int i = 0; i < m; i++) {
    int x, y, c;
    scanf("%d %d %d", &x, &y, &c);
    int l = lca(x, y);
    paths[l].push_back({c, x, y});
  }
  piv = 1;
  hld(1);
  for (int i = 1; i <= piv; i++) {
    psum[i].resize(csize[i] + 2);
  }
  solve();
  printf("%d", dp[1]);
}