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 maxn = 2e5 + 20;
const int maxb = 20;
vector<int> adj[maxn], x[maxn];
int p[maxn][maxb], st[maxn], ft[maxn], t, from[maxn], to[maxn], w[maxn],
    h[maxn];
long long fen_dp[maxn], fen_pd[maxn];
long long dp[maxn], pd[maxn];
long long get_pd(int v) {
  v = st[v];
  long long res = 0;
  for (v++; v > 0; v -= v & (-v)) res += fen_pd[v];
  return res;
}
void update_pd(int v, long long val) {
  for (v++; v < maxn; v += v & (-v)) fen_pd[v] += val;
}
long long get_dp(int v) {
  v = st[v];
  long long res = 0;
  for (v++; v > 0; v -= v & (-v)) res += fen_dp[v];
  return res;
}
void update_dp(int v, long long val) {
  for (v++; v < maxn; v += v & (-v)) fen_dp[v] += val;
}
void set_dfs(int v) {
  st[v] = ++t;
  for (auto u : adj[v]) {
    p[u][0] = v;
    for (int i = 1; i < maxb; i++) p[u][i] = p[p[u][i - 1]][i - 1];
    h[u] = h[v] + 1;
    set_dfs(u);
  }
  ft[v] = t;
}
bool is_par(int v, int u) { return st[v] <= st[u] && st[u] <= ft[v]; }
int lca(int v, int u) {
  for (int i = maxb - 1; i >= 0; i--)
    if (!is_par(p[v][i], u)) v = p[v][i];
  if (is_par(v, u)) return v;
  return p[v][0];
}
void dfs(int v) {
  for (auto u : adj[v]) dfs(u), pd[v] += dp[u];
  update_pd(st[v], pd[v]);
  update_pd(ft[v] + 1, -pd[v]);
  for (auto e : x[v]) {
    long long a = 0, b = 0;
    if (from[e] != v) a = get_pd(from[e]) - pd[v] - get_dp(from[e]);
    if (to[e] != v) b = get_pd(to[e]) - pd[v] - get_dp(to[e]);
    dp[v] = max(dp[v], w[e] + a + b + pd[v]);
  }
  dp[v] = max(dp[v], pd[v]);
  update_dp(st[v], dp[v]);
  update_dp(ft[v] + 1, -dp[v]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    p--;
    adj[p].push_back(i);
  }
  set_dfs(0);
  for (int i = 0; i < m; i++) {
    cin >> from[i] >> to[i] >> w[i];
    from[i]--;
    to[i]--;
    x[lca(from[i], to[i])].push_back(i);
  }
  dfs(0);
  cout << dp[0] << endl;
}