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;
struct Fenwick {
  int n;
  long long tree[200002];
  void init(int _n) {
    n = _n;
    fill(tree + 1, tree + n + 1, 0LL);
  }
  void upd(int x, long long val) {
    while (x <= n) {
      tree[x] += val;
      x += x & -x;
    }
  }
  long long sum(int x) {
    long long ret = 0;
    while (x) {
      ret += tree[x];
      x -= x & -x;
    }
    return ret;
  }
} tree;
struct Query {
  int u, v;
  long long cost;
  Query() {}
  Query(int u, int v, long long cost) : u(u), v(v), cost(cost) {}
};
int n, m;
int par[200002];
vector<int> child[200002];
int depth[200002], LCADB[200002][20];
long long DP[200002];
int sz[200002];
vector<Query> queryVec[200002];
int in[200002], top[200002], idx[200002];
long long DPSum[200002];
void makeTree(int x) {
  sz[x] = 1;
  for (auto &y : child[x]) {
    depth[y] = depth[x] + 1;
    makeTree(y);
    sz[x] += sz[y];
    if (sz[y] > sz[child[x][0]]) swap(child[x][0], y);
  }
}
int in_cnt;
void dfs_hld(int x) {
  in[x] = ++in_cnt;
  idx[in[x]] = x;
  for (auto y : child[x]) {
    top[y] = (child[x][0] == y) ? top[x] : y;
    dfs_hld(y);
  }
}
int getLCA(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  for (int d = 0; d < 20; d++)
    if ((depth[x] - depth[y]) & (1 << d)) x = LCADB[x][d];
  if (x == y) return x;
  for (int d = 19; d >= 0; d--)
    if (LCADB[x][d] != LCADB[y][d]) x = LCADB[x][d], y = LCADB[y][d];
  return par[x];
}
int kth_parent(int x, int k) {
  for (int d = 0; d < 20; d++) {
    if ((k >> d) & 1) x = LCADB[x][d];
  }
  return x;
}
long long pathQuery(int x, int topD) {
  long long ret = 0;
  while (depth[x] >= topD) {
    int tp = in[top[x]];
    int tStart = max(topD, depth[top[x]]) - depth[top[x]] + tp;
    int tEnd = depth[x] - depth[top[x]] + tp;
    ret += tree.sum(tEnd) - tree.sum(tStart - 1);
    x = par[top[x]];
  }
  return ret;
}
void dfs(int x) {
  long long dpSum = 0;
  for (auto y : child[x]) {
    dfs(y);
    dpSum += DP[y];
  }
  DPSum[x] = DP[x] = dpSum;
  for (auto y : child[x]) {
    tree.upd(in[y], dpSum - DP[y]);
  }
  for (auto query : queryVec[x]) {
    int tx = query.u, ty = query.v;
    long long tv = query.cost;
    assert(depth[tx] <= depth[ty]);
    long long val;
    if (tx == x) {
      val = dpSum + tv;
      val -= DP[kth_parent(ty, depth[ty] - depth[tx] - 1)];
      val += pathQuery(ty, depth[x] + 2);
      val += DPSum[ty];
    } else {
      val = dpSum + tv;
      val -= DP[kth_parent(tx, depth[tx] - depth[x] - 1)];
      val -= DP[kth_parent(ty, depth[ty] - depth[x] - 1)];
      val += pathQuery(tx, depth[x] + 2);
      val += pathQuery(ty, depth[x] + 2);
      val += DPSum[tx];
      val += DPSum[ty];
    }
    DP[x] = max(DP[x], val);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &par[i]);
    LCADB[i][0] = par[i];
    child[par[i]].push_back(i);
  }
  makeTree(1);
  top[1] = 1;
  dfs_hld(1);
  for (int d = 1; d < 20; d++)
    for (int i = 1; i <= n; i++) LCADB[i][d] = LCADB[LCADB[i][d - 1]][d - 1];
  for (int i = 1; i <= m; i++) {
    Query tmp;
    scanf("%d %d %lld", &tmp.u, &tmp.v, &tmp.cost);
    if (depth[tmp.u] > depth[tmp.v]) swap(tmp.u, tmp.v);
    int z = getLCA(tmp.u, tmp.v);
    queryVec[z].push_back(tmp);
  }
  tree.init(n);
  dfs(1);
  printf("%lld", DP[1]);
}