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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long n, m, i, j, a[200005], dp[200005], x, y, z, fa[200005][19],
    dep[200005], first[200005], ed[200005], ti;
vector<long long> e[200005];
vector<pair<pair<long long, long long>, long long> > ad[200005];
struct bit {
  long long s[200005];
  long long lowbit(long long x) { return x & (-x); }
  void add(long long x, long long y) {
    long long i;
    for (i = x; i <= n + 1; i += lowbit(i)) s[i] += y;
  }
  void add(long long l, long long r, long long y) {
    add(l, y);
    add(r + 1, -y);
  }
  long long query(long long x) {
    long long i, ss = 0;
    for (i = x; i; i -= lowbit(i)) ss += s[i];
    return ss;
  }
} t1, t2;
void dfs1(long long x) {
  first[x] = ++ti;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    dep[*it] = dep[x] + 1;
    dfs1(*it);
  }
  ed[x] = ti;
}
long long lca(long long x, long long y) {
  long long i;
  for ((i) = (18); (i) >= (0); (i)--)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  for ((i) = (18); (i) >= (0); (i)--)
    if (dep[fa[y][i]] >= dep[x]) y = fa[y][i];
  if (x == y) return x;
  for ((i) = (18); (i) >= (0); (i)--)
    if (fa[x][i] != fa[y][i]) {
      x = fa[x][i];
      y = fa[y][i];
    }
  return fa[x][0];
}
void dfs2(long long x) {
  long long s = 0;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    dfs2(*it);
    s += dp[*it];
  }
  t1.add(first[x], ed[x], s);
  dp[x] = s;
  for (__typeof((ad[x]).begin()) it = (ad[x]).begin(); it != (ad[x]).end();
       it++) {
    long long a = it->first.first, b = it->first.second, c = it->second;
    dp[x] = max(dp[x], c + t1.query(first[a]) + t1.query(first[b]) -
                           t1.query(first[x]) - t2.query(first[a]) -
                           t2.query(first[b]) + 2 * t2.query(first[x]));
  }
  t2.add(first[x], ed[x], dp[x]);
}
int main() {
  read(n);
  read(m);
  for (((i)) = (1); ((i)) <= ((n - 1)); ((i))++) {
    read(fa[i + 1][0]);
    e[fa[i + 1][0]].push_back(i + 1);
  }
  dep[1] = 1;
  dfs1(1);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++)
    for (((i)) = (1); ((i)) <= ((n)); ((i))++)
      fa[i][j] = fa[fa[i][j - 1]][j - 1];
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    read(x);
    read(y);
    read(z);
    ad[lca(x, y)].push_back(make_pair(make_pair(x, y), z));
  }
  dfs2(1);
  cout << dp[1] << endl;
  return 0;
}