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 N, M, dp[200011];
int num[200011], low[200011];
vector<int> adj[200011];
vector<pair<pair<int, int>, int> > q[200011];
struct LCA {
  int p[200011][19];
  int dpth[200011];
  void init() {
    for (int x = 1; x < 19; x++)
      for (int i = 1; i <= N; i++) p[i][x] = p[p[i][x - 1]][x - 1];
  }
  int elevate(int a, int d) {
    for (int i = 18; i >= 0; i--)
      if (d & (1 << i)) a = p[a][i];
    return a;
  }
  int find(int a, int b) {
    if (dpth[a] < dpth[b]) swap(a, b);
    a = elevate(a, dpth[a] - dpth[b]);
    if (a == b) return a;
    for (int i = 18; i >= 0; i--)
      if (p[a][i] != p[b][i]) a = p[a][i], b = p[b][i];
    return p[a][0];
  }
  int dv(int a, int b) {
    int c = find(a, b);
    if (a == b) return a;
    if (c != a) return p[a][0];
    return elevate(b, dpth[b] - dpth[a] - 1);
  }
};
struct segtree {
  int st[4 * 200011], lazy[4 * 200011];
  void push(int w, int L, int R) {
    if (!lazy[w])
      return;
    else if (L != R) {
      lazy[w * 2] += lazy[w];
      lazy[w * 2 + 1] += lazy[w];
    }
    st[w] += lazy[w];
    lazy[w] = 0;
  }
  void update(int w, int L, int R, int a, int b, int v) {
    push(w, L, R);
    if (b < L || a > R)
      return;
    else if (a <= L && b >= R) {
      lazy[w] += v;
      push(w, L, R);
    } else {
      update(w * 2, L, (L + R) / 2, a, b, v);
      update(w * 2 + 1, (L + R) / 2 + 1, R, a, b, v);
      st[w] = st[w * 2] + st[w * 2 + 1];
    }
  }
  int query(int w, int L, int R, int a, int b) {
    push(w, L, R);
    if (b < L || a > R)
      return 0;
    else if (a <= L && b >= R)
      return st[w];
    else {
      int q1 = query(w * 2, L, (L + R) / 2, a, b);
      int q2 = query(w * 2 + 1, (L + R) / 2 + 1, R, a, b);
      return q1 + q2;
    }
  }
};
LCA data;
segtree tree;
void dfs(int x) {
  static int cnt = 0;
  num[x] = (++cnt);
  int s = 0;
  for (int i = 0; i < (int)adj[x].size(); i++) {
    dfs(adj[x][i]);
    s += dp[num[adj[x][i]]];
  }
  low[x] = cnt;
  dp[num[x]] = s;
  for (int i = 0; i < (int)q[x].size(); i++) {
    int a = q[x][i].first.first;
    int b = q[x][i].first.second;
    int c = q[x][i].second;
    int v1 = tree.query(1, 1, N, num[a], num[a]);
    int v2 = tree.query(1, 1, N, num[b], num[b]);
    if (a == x || b == x) v1 += dp[num[x]];
    dp[num[x]] = max(dp[num[x]], v1 + v2 + c + s - dp[num[data.dv(x, a)]] -
                                     dp[num[data.dv(x, b)]]);
  }
  tree.update(1, 1, N, num[x], num[x], s);
  for (int i = 0; i < (int)adj[x].size(); i++)
    tree.update(1, 1, N, num[adj[x][i]], low[adj[x][i]],
                s - dp[num[adj[x][i]]]);
}
int main() {
  if (fopen("data.in", "r")) freopen("data.in", "r", stdin);
  scanf("%d", &N);
  scanf("%d", &M);
  data.p[1][0] = 1;
  data.dpth[1] = 1;
  for (int i = 2; i <= N; i++) {
    scanf("%d", &data.p[i][0]);
    adj[data.p[i][0]].push_back(i);
    data.dpth[i] = data.dpth[data.p[i][0]] + 1;
  }
  data.init();
  for (int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    q[data.find(a, b)].push_back(make_pair(make_pair(a, b), c));
  }
  dfs(1);
  printf("%d\n", dp[1]);
  return 0;
}