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;
const int MAX_LOG = 18;
const int N = 1 << MAX_LOG;
int p[MAX_LOG][N], dep[N], Time;
vector<int> children[N];
int L[N], R[N];
void dfs(int u, int f) {
  dep[u] = dep[f] + 1;
  L[u] = ++Time;
  p[0][u] = f;
  for (auto v : children[u]) {
    if (v != f) {
      dfs(v, u);
    }
  }
  R[u] = Time;
}
void init_lca(int n) {
  dfs(0, 0);
  for (int i = 1; i < MAX_LOG; i++) {
    for (int j = 0; j < n; j++) {
      p[i][j] = p[i - 1][p[i - 1][j]];
    }
  }
}
inline int jump(int u, int d) {
  if (d < 0) {
    return u;
  }
  for (int i = MAX_LOG - 1; i >= 0; i--) {
    if (d & (1 << i)) {
      u = p[i][u];
      d -= 1 << i;
    }
  }
  return u;
}
int get_lca(int a, int b) {
  if (dep[a] > dep[b]) {
    swap(a, b);
  }
  int d = dep[b] - dep[a];
  b = jump(b, d);
  if (a == b) return a;
  for (int i = MAX_LOG - 1; i >= 0; i--)
    if (p[i][a] != p[i][b]) {
      a = p[i][a];
      b = p[i][b];
    }
  return p[0][a];
}
struct Tree *pool;
struct Tree {
  Tree *lc, *rc;
  int sum, l, r, lazy;
  Tree(int l = 0, int r = 0) : l(l), r(r) {
    sum = 0;
    if (l == r) {
      return;
    }
    int m = (l + r) >> 1;
    lc = new (pool++) Tree(l, m);
    rc = new (pool++) Tree(m + 1, r);
  }
  void push() {
    lc->lazy += lazy;
    rc->lazy += lazy;
    lc->sum += lazy;
    rc->sum += lazy;
    lazy = 0;
  }
  void insert(int L, int R, int add) {
    if (L <= l && r <= R) {
      lazy += add;
      sum += add;
      return;
    }
    push();
    int m = (l + r) >> 1;
    if (L <= m) {
      lc->insert(L, R, add);
    }
    if (R > m) {
      rc->insert(L, R, add);
    }
    sum = lc->sum + rc->sum;
  }
  int query(int pos) {
    if (l == r) {
      return sum;
    }
    push();
    int m = (l + r) >> 1;
    if (pos <= m) {
      return lc->query(pos);
    } else {
      return rc->query(pos);
    }
  }
} node[N << 2], *sub_tree, *tree;
int dp[N], x[N], y[N], w[N];
vector<int> queries[N];
void solve(int u, int f) {
  int son_dp = 0;
  for (auto v : children[u]) {
    if (v != f) {
      solve(v, u);
      son_dp += dp[v];
    }
  }
  sub_tree->insert(L[u], R[u], son_dp);
  dp[u] = son_dp;
  for (auto id : queries[u]) {
    int a = x[id], b = y[id], c = w[id];
    int value = 0;
    value += sub_tree->query(L[a]);
    value += sub_tree->query(L[b]);
    value -= son_dp;
    value -= tree->query(L[a]) + tree->query(L[b]);
    if (value + c > dp[u]) {
      dp[u] = value + c;
    }
  }
  tree->insert(L[u], R[u], dp[u]);
}
int main() {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &a);
    a--;
    b = i + 1;
    children[a].push_back(b);
    children[b].push_back(a);
  }
  init_lca(n);
  pool = node;
  sub_tree = new (pool++) Tree(1, n);
  tree = new (pool++) Tree(1, n);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &x[i], &y[i], &w[i]);
    x[i]--;
    y[i]--;
    int lca = get_lca(x[i], y[i]);
    queries[lca].push_back(i);
  }
  solve(0, -1);
  printf("%d\n", dp[0]);
  return 0;
}