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;
int n, m;
const int mxn = (2e5) + 5;
vector<int> tr[mxn];
int p[mxn][20];
int dep[mxn];
int T;
int in[mxn];
int out[mxn];
void dfs(int v, int pa) {
  ++T;
  in[v] = T;
  for (int i = 0; i < tr[v].size(); ++i) {
    int u = tr[v][i];
    if (u == pa) continue;
    dep[u] = dep[v] + 1;
    p[u][0] = v;
    dfs(u, v);
  }
  out[v] = T;
}
int mxlog = 0;
void init() {
  while ((1 << mxlog) <= n) ++mxlog;
  for (int j = 1; j < mxlog; ++j)
    for (int i = 1; i <= n; ++i) p[i][j] = p[p[i][j - 1]][j - 1];
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  int dif = dep[y] - dep[x];
  for (int i = 0; i < mxlog; ++i) {
    if ((1 << i) & dif) y = p[y][i];
  }
  if (x == y) return x;
  for (int i = mxlog - 1; i >= 0; --i)
    if (p[x][i] != p[y][i]) {
      x = p[x][i];
      y = p[y][i];
    }
  return p[x][0];
}
int lz[mxn * 4];
int sum[mxn];
void pros(int p, int l, int r) {
  if (l != r) {
    lz[p * 2] += lz[p];
    lz[p * 2 + 1] += lz[p];
  } else
    sum[l] += lz[p];
  lz[p] = 0;
}
void update(int p, int l, int r, int i, int j, int x) {
  pros(p, l, r);
  if (r < i || l > j) return;
  if (l >= i && r <= j) {
    lz[p] += x;
    pros(p, l, r);
    return;
  }
  int md = (l + r) / 2;
  update(p * 2, l, md, i, j, x);
  update(p * 2 + 1, md + 1, r, i, j, x);
}
void get(int p, int l, int r, int i) {
  pros(p, l, r);
  if (r < i || l > i) return;
  if (l == r) return;
  int md = (l + r) / 2;
  if (i <= md)
    get(p * 2, l, md, i);
  else
    get(p * 2 + 1, md + 1, r, i);
}
int dp[mxn];
int dpsm[mxn];
int ans = 0;
vector<pair<int, pair<int, int> > > q[mxn];
void dfs1(int v, int pa) {
  int sm = 0;
  for (int i = 0; i < tr[v].size(); ++i) {
    int u = tr[v][i];
    if (u == pa) continue;
    dfs1(u, v);
    sm += dp[u];
    dp[v] = max(dp[v], dp[u]);
  }
  dpsm[v] = sm;
  for (int i = 0; i < tr[v].size(); ++i) {
    int u = tr[v][i];
    if (u == pa) continue;
    update(1, 1, n, in[u], out[u], sm - dp[u]);
  }
  for (int i = 0; i < q[v].size(); ++i) {
    int c = q[v][i].first;
    int a = q[v][i].second.first;
    int b = q[v][i].second.second;
    int vl = 0;
    if (a == v) {
      get(1, 1, n, in[b]);
      vl += sum[in[b]] + dpsm[b];
    } else if (b == v) {
      get(1, 1, n, in[a]);
      vl += sum[in[a]] + dpsm[a];
    } else {
      get(1, 1, n, in[b]);
      vl += sum[in[b]];
      get(1, 1, n, in[a]);
      vl += sum[in[a]];
      vl += dpsm[a] + dpsm[b];
      vl -= sm;
    }
    dp[v] = max(dp[v], vl + c);
  }
  dp[v] = max(dp[v], dpsm[v]);
  ans = max(ans, dp[v]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    tr[x].push_back(i);
    tr[i].push_back(x);
  }
  dfs(1, 1);
  init();
  for (int i = 0; i < m; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    int node = lca(x, y);
    q[node].push_back({c, {x, y}});
  }
  dfs1(1, 1);
  printf("%d\n", ans);
  return 0;
}