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 N = 2e5 + 5;
typedef int ai[N];
vector<int> G[N];
int cnt;
ai s, h, top, pa, dfn, hea;
long long dp[N];
int size(int x, int p) {
  s[x] = 1;
  for (auto i : G[x]) s[x] += size(i, x);
  return s[x];
}
void dfs(int x, int p, int t) {
  pa[x] = p, top[x] = t, h[x] = h[p] + 1, dfn[x] = ++cnt;
  int &y = hea[x] = 0;
  for (auto i : G[x])
    if (s[y] < s[i]) y = i;
  if (y) dfs(y, x, t);
  for (auto i : G[x])
    if (i != y) dfs(i, x, i);
}
void build() {
  size(1, 0);
  cnt = 0;
  dfs(1, 0, 1);
}
long long tree[N];
long long query(int x) {
  int res = 0;
  while (x) {
    res += tree[x];
    x -= x & -x;
  }
  return res;
}
void add(int x, long long c) {
  while (x <= cnt) {
    tree[x] += c;
    x += x & -x;
  }
}
long long foo(int l, int r) { return query(r) - query(l - 1); }
long long path(int x, int y, int &w, int need) {
  int X = x, Y = y;
  long long res = 0;
  while (top[x] != top[y]) {
    if (h[top[x]] >= h[top[y]]) {
      if (need) res += foo(dfn[top[x]], dfn[x]);
      int u = pa[top[x]], v = top[x];
      x = pa[top[x]];
      if (hea[u]) res += dp[hea[u]] - dp[v];
    } else
      swap(x, y);
  }
  if (dfn[x] > dfn[y]) swap(x, y);
  if (need) res += foo(dfn[x], dfn[y]);
  w = x;
  if (hea[w]) res -= dp[hea[w]];
  if (hea[X]) res += dp[hea[X]];
  if (hea[Y]) res += dp[hea[Y]];
  return res;
}
vector<pair<pair<int, int>, int>> eve[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
  }
  build();
  vector<int> all;
  for (int i = 1; i <= n; ++i) all.push_back(i);
  sort(all.begin(), all.end(), [&](int i, int j) { return h[i] > h[j]; });
  for (int rr = 0; rr < m; ++rr) {
    int u, v, c, w;
    scanf("%d%d%d", &u, &v, &c);
    path(u, v, w, 0);
    eve[w].push_back({{u, v}, c});
  }
  for (int x : all) {
    dp[x] = 0;
    for (int u : G[x]) dp[x] += dp[u];
    for (auto e : eve[x]) {
      int c = e.second;
      int u = e.first.first;
      int v = e.first.second;
      int w;
      dp[x] = max(dp[x], c + path(u, v, w, 1));
    }
    int u = pa[x], v = x;
    if (u && v != hea[u]) add(dfn[u], dp[v]);
  }
  cout << dp[1] << endl;
}