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 maxn = 2e5 + 10;
const int lg = 20;
int n, st[maxn], fi[maxn], dp[maxn], rmq[lg + 2][maxn], h[maxn], c[maxn], m,
    tmp, par[lg + 2][maxn], dp_ch[maxn];
pair<long long, long long> q[maxn];
vector<int> v[maxn], ch[lg][maxn], add[maxn];
void get_ch(int i, int j) {
  st[i] = tmp;
  par[0][i] = j;
  for (int y = 1; y <= lg; y++) par[y][i] = par[y - 1][par[y - 1][i]];
  for (int y = 0; y < v[i].size(); y++) {
    int x = v[i][y];
    tmp++;
    h[x] = h[i] + 1;
    get_ch(v[i][y], i);
    ch[0][i].push_back(v[i][y]);
  }
  for (int y = 1; y <= lg; y++)
    for (int u = 0; u < ch[y - 1][i].size(); u++)
      for (int v = 0; v < ch[y - 1][ch[y - 1][i][u]].size(); v++) {
        int x = ch[y - 1][ch[y - 1][i][u]][v];
        ch[y][i].push_back(x);
      }
  fi[i] = tmp;
}
int lca(int i, int j) {
  if (h[i] > h[j]) swap(i, j);
  for (int y = 0; y <= lg; y++) {
    if ((h[j] - h[i]) & (1 << y)) j = par[y][j];
  }
  if (i == j) return i;
  for (int y = lg; y > -1; y--) {
    if (par[y][i] != par[y][j]) i = par[y][i], j = par[y][j];
  }
  return par[0][i];
}
int RMQ(int i, int Par) {
  int ret = 0;
  for (int y = lg; y > -1; y--)
    if (h[i] - (1 << y) >= h[Par]) ret += rmq[y][i], i = par[y][i];
  return ret;
}
void dfs(int i) {
  for (int y = 0; y < v[i].size(); y++) {
    int x = v[i][y];
    dfs(x);
    dp_ch[i] += dp[x];
  }
  for (int y = 0; y < ch[0][i].size(); y++)
    rmq[0][ch[0][i][y]] = dp_ch[ch[0][i][y]] - dp[ch[0][i][y]];
  for (int y = 1; y <= lg; y++)
    for (int u = 0; u < ch[y][i].size(); u++) {
      int x = ch[y][i][u];
      rmq[y][x] = rmq[y - 1][x] + rmq[y - 1][par[y - 1][x]];
    }
  dp[i] = dp_ch[i];
  for (int y = 0; y < add[i].size(); y++) {
    int x = add[i][y];
    dp[i] =
        max(dp[i], dp_ch[i] + RMQ(q[x].first, i) + RMQ(q[x].second, i) + c[x]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (int y = 2; y <= n; y++) {
    int i;
    cin >> i;
    v[i].push_back(y);
  }
  tmp = 1;
  get_ch(1, 0);
  for (int y = 1; y <= m; y++) {
    cin >> q[y].first >> q[y].second >> c[y];
    add[lca(q[y].first, q[y].second)].push_back(y);
  }
  dfs(1);
  cout << dp[1];
}