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>
template <class T>
void scan(T &x) {
  register char ch;
  x = 0;
  for (ch = getchar(); ~ch && (ch < '0' || ch > '9'); ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int n, m;
struct SegTree {
  long long sum[200005 << 2], tag[200005 << 2];
  void clear() {
    memset(sum, 0, sizeof sum);
    memset(tag, 0, sizeof tag);
  }
  void down(int k, int l, int mid, int r) {
    if (tag[k]) {
      sum[k << 1] += (mid - l + 1) * tag[k];
      sum[k << 1 | 1] += (r - mid) * tag[k];
      tag[k << 1] += tag[k];
      tag[k << 1 | 1] += tag[k];
      tag[k] = 0;
    }
  }
  void modify(int k, int l, int r, int L, int R, long long val) {
    if (L <= l && r <= R) {
      sum[k] += (r - l + 1) * val;
      tag[k] += val;
      return;
    }
    int mid = (l + r) >> 1;
    down(k, l, mid, r);
    if (L <= mid) modify(k << 1, l, mid, L, R, val);
    if (mid < R) modify(k << 1 | 1, mid + 1, r, L, R, val);
    sum[k] = sum[k << 1] + sum[k << 1 | 1];
  }
  long long query_sum(int k, int l, int r, int L, int R) {
    if (L <= l && r <= R) return sum[k];
    int mid = (l + r) >> 1;
    down(k, l, mid, r);
    long long res = 0;
    if (L <= mid) res += query_sum(k << 1, l, mid, L, R);
    if (mid < R) res += query_sum(k << 1 | 1, mid + 1, r, L, R);
    return res;
  }
  long long at(int x) { return query_sum(1, 1, n, x, x); }
  void modify(int x, long long y) { modify(1, 1, n, x, x, y); }
} f, g;
int head[200005], nxt[200005], to[200005], ed;
void AddEdge(int u, int v) {
  nxt[++ed] = head[u];
  head[u] = ed;
  to[ed] = v;
}
int fa[200005], depth[200005], son[200005], top[200005], dfn[200005],
    idfn[200005], sz[200005], dfn_tot;
int DFS(int now) {
  sz[now] = 1;
  int maxson = 0, tmp;
  for (int i = head[now]; i; i = nxt[i]) {
    depth[to[i]] = depth[now] + 1;
    tmp = DFS(to[i]);
    sz[now] += tmp;
    if (tmp > maxson) {
      maxson = tmp;
      son[now] = to[i];
    }
  }
  return sz[now];
}
void DFS2(int now, int tp) {
  dfn[now] = ++dfn_tot;
  idfn[dfn_tot] = now;
  top[now] = tp;
  if (son[now]) DFS2(son[now], tp);
  for (int i = head[now]; i; i = nxt[i]) {
    if (to[i] == son[now]) continue;
    DFS2(to[i], to[i]);
  }
}
int LCA(int u, int v) {
  while (top[u] != top[v]) {
    if (depth[top[u]] < depth[top[v]]) std::swap(u, v);
    u = fa[top[u]];
  }
  return depth[u] < depth[v] ? u : v;
}
int SON(int u, int Fa) {
  while (top[u] != top[Fa]) {
    if (fa[top[u]] == Fa) return top[u];
    u = fa[top[u]];
  }
  return idfn[dfn[Fa] + 1];
}
struct Query {
  int u, v, c;
  Query() {}
  Query(int u, int v, int c) : u(u), v(v), c(c) {}
};
std::vector<Query> qry[200005];
void DFS3(int now) {
  long long sum = 0;
  for (int i = head[now]; i; i = nxt[i]) {
    DFS3(to[i]);
    sum += f.at(dfn[to[i]]);
  }
  long long F = sum;
  for (auto it : qry[now]) {
    int u = it.u, v = it.v, c = it.c;
    if (u == now)
      F = std::max(F, sum - f.at(dfn[SON(v, now)]) + g.at(dfn[v]) + c);
    else
      F = std::max(F, sum - f.at(dfn[SON(u, now)]) - f.at(dfn[SON(v, now)]) +
                          g.at(dfn[u]) + g.at(dfn[v]) + c);
  }
  f.modify(dfn[now], F);
  for (int i = head[now]; i; i = nxt[i]) {
    g.modify(1, 1, n, dfn[to[i]], dfn[to[i]] + sz[to[i]] - 1,
             sum - f.at(dfn[to[i]]));
  }
  g.modify(dfn[now], sum);
}
int main() {
  memset(head, 0, sizeof head);
  ed = 0;
  scan(n);
  scan(m);
  for (int i = 2; i <= n; ++i) {
    scan(fa[i]);
    AddEdge(fa[i], i);
  }
  dfn_tot = 0;
  DFS(1);
  DFS2(1, 1);
  for (int i = 1; i <= n; ++i) qry[i].clear();
  for (int u, v, c, i = 1; i <= m; ++i) {
    scan(u);
    scan(v);
    scan(c);
    if (dfn[u] > dfn[v]) std::swap(u, v);
    int lca = LCA(u, v);
    qry[lca].push_back(Query(u, v, c));
  }
  f.clear();
  g.clear();
  DFS3(1);
  printf("%I64d\n", f.at(dfn[1]));
  return 0;
}