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 read() {
  char s;
  int x = 0, f = 1;
  s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x *= 10;
    x += s - '0';
    s = getchar();
  }
  return x * f;
}
const int N = 2e5 + 5;
int n, m;
vector<int> v[N], q[N];
int dep[N];
int p[25][N];
int ti, in[N], out[N];
void go(int x, int fa) {
  dep[x] = dep[fa] + 1;
  p[0][x] = fa;
  ti++;
  in[x] = ti;
  for (int i = 0; i < v[x].size(); i++) {
    int k = v[x][i];
    if (k == fa) continue;
    go(k, x);
  }
  out[x] = ti;
}
void work() {
  for (int i = 1; i <= 24; i++) {
    for (int j = 1; j <= n; j++) {
      p[i][j] = p[i - 1][p[i - 1][j]];
    }
  }
}
int lca(int x, int y) {
  if (dep[x] >= dep[y]) swap(x, y);
  for (int i = 24; i >= 0; i--)
    if (dep[p[i][y]] >= dep[x]) y = p[i][y];
  if (x == y) return x;
  for (int i = 24; i >= 0; i--)
    if (p[i][x] != p[i][y]) x = p[i][x], y = p[i][y];
  return p[0][x];
}
struct pace {
  int x, y, w;
} pa[N];
int dp[N];
struct tree {
  int c[N];
  void clear() { memset(c, 0, sizeof(c)); }
  int lowbit(int x) { return x & (-x); }
  void modify(int pos, int x) {
    for (int i = pos; i <= n; i += lowbit(i)) {
      c[i] += x;
    }
  }
  int query(int pos) {
    int ans = 0;
    for (int i = pos; i > 0; i -= lowbit(i)) {
      ans += c[i];
    }
    return ans;
  }
} t;
void dfs(int x, int fa) {
  int rec = 0;
  for (int i = 0; i < v[x].size(); i++) {
    int k = v[x][i];
    if (k == fa) continue;
    dfs(k, x);
    rec += dp[k];
  }
  dp[x] = rec;
  for (int i = 0; i < q[x].size(); i++) {
    int id = q[x][i];
    int a = pa[id].x;
    int b = pa[id].y;
    int w = pa[id].w;
    dp[x] = max(dp[x], rec + t.query(in[a]) + t.query(in[b]) + w);
  }
  t.modify(in[x], rec - dp[x]);
  t.modify(out[x] + 1, dp[x] - rec);
}
int main() {
  n = read(), m = read();
  for (int i = 2; i <= n; i++) {
    int x = read();
    v[x].push_back(i);
    v[i].push_back(x);
  }
  go(1, 0);
  work();
  for (int i = 1; i <= m; i++) {
    pa[i].x = read(), pa[i].y = read();
    pa[i].w = read();
    q[lca(pa[i].x, pa[i].y)].push_back(i);
  }
  dfs(1, 0);
  printf("%d\n", dp[1]);
}