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 INF = (int)2e9 + 10;
const int mod = (int)1e9 + 7;
const int N = (int)1e6 + 10;
const long long LLINF = (long long)8e18 + 10;
const double pi = acos(-1.0);
template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {
  if (x > y) return x = y, true;
  return false;
}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {
  if (x < y) return x = y, true;
  return false;
}
template <typename T>
T getint() {
  char c = getchar();
  T p = 1, x = 0;
  while (c == ' ' || c == '\n') c = getchar();
  if (c == '-') p = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * p;
}
int sp[22][N];
int ans[N], dp[N], n, m, d[N];
vector<int> g[N];
int le[N], ri[N], timer;
vector<tuple<int, int, int> > h[N];
void dfs(int v, int p) {
  sp[0][v] = p;
  le[v] = ++timer;
  for (int i = 0; i < g[v].size(); ++i) {
    int u = g[v][i];
    if (u == p) continue;
    d[u] = d[v] + 1;
    dfs(u, v);
  }
  ri[v] = timer;
}
void build() {
  for (int i = 1; i < 20; ++i) {
    for (int j = 1; j <= n; ++j) {
      sp[i][j] = sp[i - 1][sp[i - 1][j]];
    }
  }
}
struct tree {
  int l, r, sum;
  tree() {}
};
tree t[N];
void build_tree(int v, int l, int r) {
  t[v].l = l;
  t[v].r = r;
  t[v].sum = 0;
  if (l == r) return;
  build_tree(v + v, l, (l + r) / 2);
  build_tree(v + v + 1, (l + r) / 2 + 1, r);
}
int get(int v, int id) {
  if (t[v].l == t[v].r) return t[v].sum;
  if (id <= (t[v].l + t[v].r) / 2)
    return t[v].sum + get(v + v, id);
  else
    return t[v].sum + get(v + v + 1, id);
}
void update(int v, int l, int r, int val) {
  if (t[v].l > r || t[v].r < l) return;
  if (l <= t[v].l && t[v].r <= r) {
    t[v].sum += val;
    return;
  }
  update(v + v, l, r, val);
  update(v + v + 1, l, r, val);
}
int lca(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  for (int i = 19; i >= 0; --i) {
    if (d[a] - (1 << i) >= d[b]) a = sp[i][a];
  }
  if (a == b) return a;
  for (int i = 19; i >= 0; --i) {
    if (sp[i][a] != sp[i][b]) a = sp[i][a], b = sp[i][b];
  }
  return sp[0][a];
}
void solve(int v) {
  for (int i = 0; i < g[v].size(); ++i) {
    int u = g[v][i];
    if (u == sp[0][v]) continue;
    solve(u);
    dp[v] += ans[u];
  }
  ans[v] = dp[v];
  for (int i = 0; i < g[v].size(); ++i) {
    int u = g[v][i];
    if (u == sp[0][v]) continue;
    update(1, le[u], ri[u], dp[v] - ans[u]);
  }
  for (int i = 0; i < h[v].size(); ++i) {
    int x, y, c;
    tie(x, y, c) = h[v][i];
    if (x != v && y != v)
      umax(ans[v], get(1, le[x]) + get(1, le[y]) - dp[v] + c);
    else {
      if (x != v) swap(x, y);
      umax(ans[v], get(1, le[y]) + c);
    }
  }
  update(1, le[v], le[v], dp[v]);
}
int main() {
  srand(time(NULL));
  n = getint<int>();
  m = getint<int>();
  for (int i = 2; i <= n; ++i) {
    int x = getint<int>();
    g[x].push_back(i);
    g[i].push_back(x);
  }
  dfs(1, 1);
  build();
  build_tree(1, 1, n);
  for (int i = 0; i < m; ++i) {
    int x = getint<int>(), y = getint<int>(), c = getint<int>();
    h[lca(x, y)].push_back(make_tuple(x, y, c));
  }
  solve(1);
  printf("%d\n", ans[1]);
}