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;
using ll = long long;
template <typename A, typename B>
ostream &operator<<(ostream &out, pair<A, B> p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <typename A,
          typename B = typename enable_if<!is_same<A, string>::value,
                                          typename A::value_type>::type>
ostream &operator<<(ostream &out, A vector) {
  out << '{';
  string sep;
  for (B x : vector) out << sep << x, sep = ", ";
  return out << '}';
}
void dbg_print() { cerr << endl; }
template <typename A, typename... B>
void dbg_print(A a, B... b) {
  cerr << ' ' << a;
  dbg_print(b...);
}
template <int N>
struct segtree {
  int n, tree[N << 1];
  segtree() { fill(tree, tree + (N << 1), 0); }
  inline void update(int pos, int delta) {
    pos += n, tree[pos] += delta;
    for (pos >>= 1; pos; pos >>= 1)
      tree[pos] = tree[pos << 1] + tree[pos << 1 | 1];
  }
  inline int get(int l, int r) const {
    int sum = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) sum += tree[l++];
      if (r & 1) sum += tree[--r];
    }
    return sum;
  }
};
const int N = 2e5 + 1;
const int LG = 19;
vector<int> g[N];
int n, m, par[N][LG], tin[N], tout[N], timer, sz[N], head[N];
segtree<N> sum_one, sum_all;
struct edge {
  int from, to, w;
};
vector<edge> qry[N];
int dp[N];
void dfs1(int v) {
  sz[v] = 1;
  for (int i = 1; i < LG; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  for (auto u : g[v]) {
    par[u][0] = v;
    dfs1(u);
    sz[v] += sz[u];
  }
  sort((g[v]).begin(), (g[v]).end(),
       [&](int a, int b) { return sz[a] > sz[b]; });
}
inline bool is_par(int v, int u) {
  return tin[v] <= tin[u] && tout[u] <= tout[v];
}
inline int lca(int v, int u) {
  if (is_par(v, u)) return v;
  for (int i = LG - 1; i >= 0; i--)
    if (!is_par(par[v][i], u)) v = par[v][i];
  return par[v][0];
}
void dfs2(int v) {
  tin[v] = timer++;
  for (int i = 0; i < ((int)((g[v]).size())); i++) {
    int u = g[v][i];
    head[u] = (i ? u : head[v]);
    dfs2(u);
  }
  tout[v] = timer;
}
inline void update(int v, int delta, segtree<N> &tree) {
  tree.update(tin[v], delta);
}
inline int get(int v, int u, segtree<N> &tree) {
  assert(is_par(u, v));
  int sum = 0;
  for (; head[v] != head[u]; v = par[head[v]][0])
    sum += tree.get(tin[head[v]], tin[v] + 1);
  return sum + tree.get(tin[u], tin[v] + 1);
}
void dfs3(int v) {
  int tot = 0;
  for (auto u : g[v]) {
    dfs3(u);
    tot += dp[u];
  }
  update(v, dp[v] = tot, sum_all);
  for (auto [a, b, w] : qry[v]) {
    if (tin[b] > tin[a]) swap(a, b);
    int sum_dp_a = get(a, v, sum_one);
    int tot_sum_a = get(a, v, sum_all);
    if (b == v) {
      dp[v] = max(dp[v], tot_sum_a - sum_dp_a + w);
    } else {
      int sum_dp_b = get(b, v, sum_one);
      int tot_sum_b = get(b, v, sum_all);
      dp[v] = max(dp[v], tot_sum_a - sum_dp_a + tot_sum_b - sum_dp_b - tot + w);
    }
  }
  update(v, dp[v], sum_one);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    cin >> par[i][0], par[i][0]--;
    g[par[i][0]].push_back(i);
  }
  dfs1(0);
  sum_one.n = sum_all.n = n;
  dfs2(0);
  for (int i = 0; i < m; i++) {
    int v, u, w;
    cin >> v >> u >> w, v--, u--;
    qry[lca(v, u)].push_back({v, u, w});
  }
  dfs3(0);
  cout << dp[0] << '\n';
}