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 MAXN = 200010;
int nowarn;
int n, m;
namespace Tree {
int head[MAXN], nxt[MAXN], to[MAXN], eidx;
void init() {
  eidx = 0;
  memset(head, -1, sizeof(head));
}
void adde(int u, int v) { to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++; }
}  // namespace Tree
namespace DFN {
int dfn[MAXN], dfn_cnt, son[MAXN], dep[MAXN], top[MAXN], size[MAXN], pa[MAXN];
void dfs1(int u, int fa, int d) {
  using namespace Tree;
  pa[u] = fa, dep[u] = d, son[u] = 0, size[u] = 1;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    dfs1(v, u, d + 1);
    size[u] += size[v];
    if (size[v] > size[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int tp) {
  using namespace Tree;
  top[u] = tp, dfn[u] = ++dfn_cnt;
  if (son[u]) dfs2(son[u], tp);
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (v == son[u]) continue;
    dfs2(v, v);
  }
}
void prelude() {
  size[0] = dfn_cnt = 0;
  dfs1(1, 0, 1);
  dfs2(1, 1);
}
int lca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = pa[top[u]];
  }
  return min(u, v);
}
}  // namespace DFN
int lowbit(int x) { return x & (-x); }
struct BIT {
  long long c[MAXN];
  void init() { memset(c, 0, sizeof(c)); }
  void add(int p, long long v) {
    for (; p <= n; p += lowbit(p)) c[p] += v;
  }
  long long sum(int p) const {
    long long s = 0;
    for (; p; p -= lowbit(p)) s += c[p];
    return s;
  }
  long long sum(int l, int r) const { return sum(r) - sum(l - 1); }
};
struct Triple {
  int first, second, val;
  Triple() {}
  Triple(int a, int b, int c) : first(a), second(b), val(c) {}
};
vector<Triple> chain[MAXN];
BIT sf, sg;
long long query(int u, int v, const BIT &bit) {
  using namespace DFN;
  long long s = 0;
  while (top[u] != top[v]) {
    s += bit.sum(dfn[top[v]], dfn[v]);
    v = pa[top[v]];
  }
  s += bit.sum(dfn[u], dfn[v]);
  return s;
}
long long f[MAXN], g[MAXN];
void dp(int u) {
  using namespace Tree;
  using namespace DFN;
  g[u] = 0;
  for (int i = head[u]; ~i; i = nxt[i]) dp(to[i]), g[u] += f[to[i]];
  sg.add(dfn[u], g[u]);
  f[u] = g[u];
  for (int i = 0; i < (int)chain[u].size(); ++i) {
    Triple tp = chain[u][i];
    int s = tp.first, t = tp.second, w = tp.val;
    if (t == u) swap(s, t);
    if (s == u) {
      f[u] = max(f[u], query(u, t, sg) - query(u, t, sf) + w);
    } else {
      f[u] = max(f[u], query(u, s, sg) + query(u, t, sg) - g[u] -
                           query(u, s, sf) - query(u, t, sf) + w);
    }
  }
  sf.add(dfn[u], f[u]);
}
int main() {
  nowarn = scanf("%d%d", &n, &m);
  Tree::init();
  for (int i = 2; i <= n; ++i) {
    int p;
    nowarn = scanf("%d", &p);
    Tree::adde(p, i);
  }
  DFN::prelude();
  while (m--) {
    int u, v, w;
    nowarn = scanf("%d%d%d", &u, &v, &w);
    int lca = DFN::lca(u, v);
    chain[lca].push_back(Triple(u, v, w));
  }
  sf.init(), sg.init();
  dp(1);
  printf("%lld\n", f[1]);
  return 0;
}