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>
#pragma GCC optimize("Ofast", "inline")
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int N = 200005;
int n, m;
vector<int> e[N], id[N];
struct Edge {
  int x, y, z;
} a[N];
int depth[N], size[N], son[N], fa[N], top[N], I[N], aI[N], Time = 0;
void dfs1(int x, int pre, int d) {
  depth[x] = d, fa[x] = pre, size[x] = 1, son[x] = 0;
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y != pre) {
      dfs1(y, x, d + 1);
      size[x] += size[y];
      if (!son[x] || size[y] > size[son[x]]) son[x] = y;
    }
  }
}
void dfs2(int x, int Top) {
  top[x] = Top;
  I[x] = ++Time;
  aI[Time] = x;
  if (son[x]) dfs2(son[x], Top);
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y != fa[x] && y != son[x]) dfs2(y, y);
  }
}
long long c[N];
void Add(int x, long long v) {
  for (; x <= n; x += x & -x) c[x] += v;
}
long long Ask(int x) {
  long long ans = 0;
  for (; x; x -= x & -x) ans += c[x];
  return ans;
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (depth[top[x]] < depth[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return depth[x] < depth[y] ? x : y;
}
int Goup(int x, int y) {
  while (top[x] != top[y]) {
    x = top[x];
    if (fa[x] == y) return x;
    x = fa[x];
  }
  return son[y];
}
long long dp[N], val[N];
long long Query(int x, int y) {
  long long ans = dp[son[x]];
  while (top[x] != top[y]) {
    ans += Ask(I[x]) - Ask(I[top[x]] - 1);
    ans -= dp[top[x]];
    x = fa[top[x]];
    ans += dp[son[x]];
  }
  ans += Ask(I[x]) - Ask(I[y] - 1);
  return ans;
}
void dfs3(int x) {
  dp[x] = 0;
  for (int i = 0; i < e[x].size(); i++) {
    int y = e[x][i];
    if (y != fa[x]) {
      dfs3(y);
      dp[x] += dp[y];
      if (y != son[x]) val[x] += dp[y];
    }
  }
  Add(I[x], val[x]);
  for (int cly = 0; cly < id[x].size(); cly++) {
    int i = id[x][cly];
    dp[x] = max(dp[x], Query(a[i].x, x) + Query(a[i].y, x) - val[x] -
                           dp[son[x]] + a[i].z);
  }
}
int main() {
  n = read();
  if (1) m = read();
  for (int i = 1; i <= n - 1; i++) {
    if (1) {
      int f = read();
      e[i + 1].push_back(f), e[f].push_back(i + 1);
    } else {
      int x = read(), y = read();
      e[x].push_back(y), e[y].push_back(x);
    }
  }
  dfs1(1, 0, 0);
  dfs2(1, 1);
  if (!1) m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    a[i].x = x, a[i].y = y, a[i].z = z;
    id[LCA(x, y)].push_back(i);
  }
  dfs3(1);
  cout << dp[1] << endl;
  return 0;
}