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;
vector<vector<long long> > g;
vector<long long> dp;
vector<vector<long long> > pred;
long long t;
long long timer = 0;
vector<long long> tin, tout;
void dfs(long long v) {
  tin[v] = timer++;
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    dfs(to);
    pred[to][0] = v;
  }
  tout[v] = timer++;
}
bool pr(long long a, long long b) {
  return tin[a] <= tin[b] && tout[a] >= tout[b];
}
vector<vector<vector<long long> > > query;
vector<long long> ind;
vector<long long> fenv;
long long ans(long long x) {
  long long sum = 0;
  while (x >= 0) {
    sum += fenv[x];
    x = (x & (x + 1)) - 1;
  }
  return sum;
}
void update(long long x, long long val) {
  if (x == -1) {
    return;
  }
  while (x < 2 * n) {
    fenv[x] += val;
    x = x | (x + 1);
  }
}
void dfs1(long long v) {
  long long sum1 = 0;
  for (long long i = 0; i < g[v].size(); i++) {
    dfs1(g[v][i]);
    sum1 += dp[g[v][i]];
  }
  dp[v] = sum1;
  for (long long i = 0; i < query[v].size(); i++) {
    long long a = query[v][i][2];
    long long b = query[v][i][3];
    long long a1 = query[v][i][0];
    long long b1 = query[v][i][1];
    long long c = query[v][i][4];
    long long sum = c;
    if (a != v) {
      sum += ans(tin[a]) - ans(tin[v]);
    }
    if (b != v) {
      sum += ans(tin[b]) - ans(tin[v]);
    }
    sum += ans(tin[v]);
    if (v != 0) {
      sum -= ans(tin[pred[v][0]]);
    }
    dp[v] = max(dp[v], sum);
  }
  update(tin[v], -dp[v]);
  update(tout[v], dp[v]);
  update(tin[pred[v][0]], dp[v]);
  update(tout[pred[v][0]], -dp[v]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  g.resize(n);
  fenv.resize(2 * n);
  ind.resize(n);
  t = log2(n) + 1;
  tin.resize(n);
  query.resize(n);
  tout.resize(n);
  pred.resize(n, vector<long long>(t));
  dp.resize(n);
  for (long long i = 1; i < n; i++) {
    long long x;
    cin >> x;
    x--;
    g[x].push_back(i);
  }
  pred[0][0] = 0;
  dfs(0);
  for (long long i = 1; i < t; i++) {
    for (long long j = 0; j < n; j++) {
      pred[j][i] = pred[pred[j][i - 1]][i - 1];
    }
  }
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    long long a2 = a, b2 = b;
    long long a1 = a;
    for (long long j = t - 1; j >= 0; j--) {
      if (!pr(pred[a1][j], b)) {
        a1 = pred[a1][j];
      }
    }
    if (!pr(a1, b)) {
      a1 = pred[a1][0];
    }
    for (long long j = t - 1; j >= 0; j--) {
      if (!pr(pred[a][j], b)) {
        a = pred[a][j];
      }
    }
    for (long long j = t - 1; j >= 0; j--) {
      if (!pr(pred[b][j], a)) {
        b = pred[b][j];
      }
    }
    query[a1].push_back({a, b, a2, b2, c});
  }
  dfs1(0);
  cout << dp[0];
  return 0;
}