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>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
int stt[MAXN], fnt[MAXN], ras[MAXN], timer = 1;
int par[MAXN], head[MAXN], h[MAXN], sz[MAXN];
int dp[MAXN], sum[MAXN];
long long fen[MAXN];
vector<int> G[MAXN];
vector<pair<pair<int, int>, int> > vec[MAXN];
void dfs1(int node, int hd) {
  ras[stt[node] = timer++] = node;
  head[node] = hd;
  int big = 0;
  for (int v : G[node])
    if (sz[v] > sz[big]) big = v;
  if (big) dfs1(big, hd);
  for (int v : G[node])
    if (v != big) dfs1(v, v);
  fnt[node] = timer;
}
inline int Lca(int x, int y) {
  while (head[x] != head[y]) {
    if (h[head[x]] < h[head[y]]) swap(x, y);
    x = par[head[x]];
  }
  if (h[x] > h[y]) swap(x, y);
  return x;
}
inline void add(int pos, int x) {
  for (; pos < MAXN; pos += pos & -pos) fen[pos] += x;
}
inline int get(int pos) {
  int res = 0;
  for (; pos; pos -= pos & -pos) res += fen[pos];
  return res;
}
void dfs2(int node) {
  for (int v : G[node]) {
    dfs2(v);
    sum[node] += dp[v];
  }
  dp[node] = sum[node];
  for (pair<pair<int, int>, int> p : vec[node]) {
    int tmp = get(stt[p.first.first]) + get(stt[p.first.second]);
    tmp += sum[node] + p.second;
    dp[node] = max(dp[node], tmp);
  }
  add(stt[node], sum[node] - dp[node]);
  add(fnt[node], dp[node] - sum[node]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 2; i <= n; i++)
    cin >> par[i], h[i] = h[par[i]] + 1, G[par[i]].push_back(i);
  for (int i = n; i > 1; i--) sz[par[i]] += ++sz[i];
  dfs1(1, 1);
  while (m--) {
    cin >> u >> v >> x;
    vec[Lca(u, v)].push_back({{u, v}, x});
  }
  dfs2(1);
  cout << dp[1] << '\n';
  return 0;
}