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;
struct R {
  int to, nex;
} r[404000];
int hea[202000] = {0}, cnt = 1, g[202000], s[202000];
int fa[202000], top[202000], dep[202000] = {0}, bs[202000] = {0}, sz[202000],
                             id[202000], tid = 0;
struct L {
  int u, v, w;
} tmp;
vector<L> vec[202000];
namespace bit_g {
int c[202000];
void RE() { memset(c, 0, sizeof c); }
void A(int x, int v) {
  for (int i = x; i <= n; i += (i & -i)) {
    c[i] += v;
  }
}
int que(int x) {
  int t = 0;
  for (int i = x; i > 0; i -= (i & -i)) {
    t += c[i];
  }
  return t;
}
int Q(int st, int en) { return que(en) - que(st - 1); }
}  // namespace bit_g
namespace bit_s {
int c[202000];
void RE() { memset(c, 0, sizeof c); }
void A(int x, int v) {
  for (int i = x; i <= n; i += (i & -i)) {
    c[i] += v;
  }
}
int que(int x) {
  int t = 0;
  for (int i = x; i > 0; i -= (i & -i)) {
    t += c[i];
  }
  return t;
}
int Q(int st, int en) { return que(en) - que(st - 1); }
}  // namespace bit_s
void pre(int x, int fff) {
  fa[x] = fff;
  dep[x] = dep[fff] + 1;
  sz[x] = 1;
  int y;
  for (int i = hea[x]; i > 0; i = r[i].nex) {
    y = r[i].to;
    if (y == fff) continue;
    pre(y, x);
    sz[x] += sz[y];
    if (sz[y] > sz[bs[x]]) bs[x] = y;
  }
}
void pour_shit(int x, int ttt) {
  id[x] = ++tid;
  top[x] = ttt;
  if (bs[x]) pour_shit(bs[x], ttt);
  int y;
  for (int i = hea[x]; i > 0; i = r[i].nex) {
    y = r[i].to;
    if (y == fa[x] || y == bs[x]) continue;
    pour_shit(y, y);
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  if (dep[x] < dep[y]) swap(x, y);
  return y;
}
int from(int x, int y) {
  while (top[x] != top[y]) {
    if (fa[top[x]] == y) return top[x];
    x = fa[top[x]];
  }
  return bs[y];
}
int asks(int x, int y) {
  int res = 0;
  while (top[x] != top[y]) {
    res += bit_s::Q(id[top[x]], id[x]);
    x = fa[top[x]];
  }
  res += bit_s::Q(id[y], id[x]);
  return res;
}
int askg(int x, int y) {
  int res = 0;
  while (top[x] != top[y]) {
    res += bit_g::Q(id[top[x]], id[x]);
    x = fa[top[x]];
  }
  res += bit_g::Q(id[y], id[x]);
  return res;
}
void dfs(int x) {
  g[x] = s[x] = 0;
  int y, t, fr;
  for (int i = hea[x]; i > 0; i = r[i].nex) {
    y = r[i].to;
    if (y == fa[x]) continue;
    dfs(y);
    s[x] += g[y];
  }
  g[x] = s[x];
  for (int i = 0; i < (int)vec[x].size(); i++) {
    tmp = vec[x][i];
    t = s[x];
    for (int ttt = 0; ttt < 2; ttt++) {
      if (tmp.u != x) {
        fr = from(tmp.u, x);
        t += asks(tmp.u, fr) - askg(tmp.u, fr);
      }
      swap(tmp.u, tmp.v);
    }
    g[x] = max(g[x], t + tmp.w);
  }
  bit_s::A(id[x], s[x]);
  bit_g::A(id[x], g[x]);
}
int main() {
  bit_g::RE();
  bit_s::RE();
  scanf("%d%d", &n, &m);
  int x, y, z;
  for (int i = 1; i < n; i++) {
    scanf("%d", &y);
    x = i + 1;
    r[++cnt] = (R){y, hea[x]};
    hea[x] = cnt;
    r[++cnt] = (R){x, hea[y]};
    hea[y] = cnt;
  }
  pre(1, 0);
  pour_shit(1, 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    vec[lca(x, y)].push_back((L){x, y, z});
  }
  dfs(1);
  printf("%d\n", g[1]);
}