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;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 2e5 + 10, maxm = 1e5 + 10, lg = 18, mod = 1e9 + 7, inf = 1e18;
int n, m, f[maxn][2], w[maxn];
vector<int> son[maxn], pp[maxn];
int par[maxn][lg + 1], h[maxn], st[maxn], ft[maxn], tt;
int dp[maxn], pd[maxn], bit[maxn][2];
void radd(int i, int x, bool b) {
  for (; i < maxn; i += (-i & i)) bit[i][b] += x;
}
void add(int i, int x, bool b) { radd(st[i], x, b), radd(ft[i] + 1, -x, b); }
int get(int i, bool b) {
  i = st[i];
  int ret = 0;
  for (; i; i -= (-i & i)) ret += bit[i][b];
  return ret;
}
void pfs(int v = 1) {
  st[v] = ++tt;
  h[v] = h[par[v][0]] + 1;
  for (int i = 1; i <= lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  for (auto u : son[v]) pfs(u);
  ft[v] = tt;
}
int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  int x = h[v] - h[u];
  for (int i = 0; i <= lg; i++)
    if (x >> i & 1) v = par[v][i];
  if (v == u) return v;
  for (int i = lg; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
int dfs(int v = 1) {
  for (auto u : son[v]) pd[v] += dfs(u);
  add(v, pd[v], 0);
  dp[v] = pd[v];
  for (auto e : pp[v]) {
    int a[2];
    a[0] = a[1] = 0;
    for (bool bb : {0, 1})
      if (f[e][bb] != v) a[bb] = get(f[e][bb], 0) - get(f[e][bb], 1) - pd[v];
    dp[v] = max(dp[v], a[0] + a[1] + pd[v] + w[e]);
  }
  add(v, dp[v], 1);
  return dp[v];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    cin >> par[i][0];
    son[par[i][0]].push_back(i);
  }
  pfs();
  for (int i = 0; i < m; i++) {
    cin >> f[i][0] >> f[i][1] >> w[i];
    pp[lca(f[i][0], f[i][1])].push_back(i);
  }
  cout << dfs();
  return 0;
}