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 long long maxn = 2e5 + 500;
const long long logg = 22;
long long par[maxn][logg];
long long dpsum[maxn][logg];
long long childsum[maxn][logg];
vector<long long> child[maxn];
long long s[maxn];
long long e[maxn];
long long timee = 0;
pair<long long, pair<long long, long long> > r[maxn];
vector<long long> kk[maxn];
long long dp[maxn];
bool pr = 0;
bool is_par(long long a, long long b) {
  if (s[a] <= s[b] && e[a] >= e[b]) return 1;
  return 0;
}
long long lca(long long a, long long b) {
  if (is_par(a, b)) {
    return a;
  }
  if (is_par(b, a)) {
    return b;
  }
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      a = par[a][i];
    }
  }
  return par[a][0];
}
long long lcaa(long long a, long long b) {
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      a = par[a][i];
    }
  }
  return a;
}
void set_se(long long a) {
  s[a] = timee;
  timee++;
  for (long long i = 0; i < child[a].size(); i++) {
    set_se(child[a][i]);
  }
  e[a] = timee;
  timee++;
}
void set_dpsum(long long a, long long i) {
  if (dpsum[a][i] != -1) {
    return;
  }
  long long v = par[a][i - 1];
  set_dpsum(v, i - 1);
  set_dpsum(a, i - 1);
  dpsum[a][i] = dpsum[a][i - 1] + dpsum[v][i - 1];
}
long long lcas(long long a, long long b) {
  if (a == b) {
    return 0;
  }
  long long ans = 0;
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      set_dpsum(a, i);
      ans += dpsum[a][i];
      a = par[a][i];
    }
  }
  return ans + dp[a];
}
void set_childsum(long long a, long long i) {
  if (childsum[a][i] != -1) {
    return;
  }
  long long v = par[a][i - 1];
  set_childsum(v, i - 1);
  set_childsum(a, i - 1);
  childsum[a][i] = childsum[a][i - 1] + childsum[v][i - 1];
}
long long lcaaa(long long a, long long b) {
  if (a == b) {
    return 0;
  }
  long long ans = 0;
  for (long long i = logg - 1; i >= 0; i--) {
    if (!is_par(par[a][i], b)) {
      set_childsum(a, i);
      ans += childsum[a][i];
      a = par[a][i];
    }
  }
  return ans + childsum[a][0];
}
void dfs(long long a) {
  long long sum = 0;
  for (long long i = 0; i < child[a].size(); i++) {
    dfs(child[a][i]);
    sum += dp[child[a][i]];
  }
  childsum[a][0] = sum;
  dp[a] = sum;
  for (long long i = 0; i < kk[a].size(); i++) {
    long long v = r[kk[a][i]].second.first;
    long long u = r[kk[a][i]].second.second;
    if (v == a || u == a) {
      v = v ^ a ^ u;
      long long ss = sum;
      long long vv = lcaa(v, a);
      ss -= dp[vv];
      ss += r[kk[a][i]].first;
      ss -= lcas(v, vv);
      ss += lcaaa(v, a);
      dp[a] = max(dp[a], ss);
    } else {
      long long ss = sum;
      long long uu = lcaa(u, a);
      long long vv = lcaa(v, a);
      ss -= dp[uu];
      ss -= dp[vv];
      ss += r[kk[a][i]].first;
      ss -= lcas(v, vv);
      ss -= lcas(u, uu);
      ss += lcaaa(v, a);
      ss += lcaaa(u, a);
      dp[a] = max(dp[a], ss);
    }
  }
  dpsum[a][0] = dp[a];
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n; i++) {
    long long v;
    cin >> v;
    v--;
    par[i][0] = v;
    child[v].push_back(i);
  }
  set_se(0);
  par[0][0] = 0;
  for (long long i = 1; i < logg; i++) {
    for (long long j = 0; j < n; j++) {
      par[j][i] = par[par[j][i - 1]][i - 1];
    }
  }
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    v--;
    u--;
    r[i] = make_pair(w, make_pair(u, v));
    kk[lca(v, u)].push_back(i);
  }
  for (long long i = 0; i < logg; i++) {
    for (long long j = 0; j < n; j++) {
      dpsum[j][i] = -1;
      childsum[j][i] = -1;
    }
  }
  dfs(0);
  for (long long i = 0; i < 1; i++) {
    cout << dp[i] << "   ";
  }
}