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;
vector<int> g[200002];
vector<pair<int, pair<int, int> > > first[200002];
int lvl[200002];
int p[20][200002];
int h[20][200002];
int d[200002][2];
inline int lca(int v1, int v2) {
  if (lvl[v1] < lvl[v2]) swap(v1, v2);
  for (int i = 20 - 1; i >= 0; --i) {
    if (lvl[p[i][v1]] >= lvl[v2]) {
      v1 = p[i][v1];
    }
  }
  if (v1 == v2) return v1;
  for (int i = 20 - 1; i >= 0; --i) {
    if (p[i][v1] != p[i][v2]) {
      v1 = p[i][v1];
      v2 = p[i][v2];
    }
  }
  return p[0][v1];
}
void dfs(int v = 0, int level = 0, int pr = 0) {
  lvl[v] = level;
  p[0][v] = pr;
  for (int i = 1; i < 20; ++i) p[i][v] = p[i - 1][p[i - 1][v]];
  for (const int& v2 : g[v]) {
    dfs(v2, level + 1, v);
  }
}
inline int getit(int v, int k) {
  if (h[k][v] != -1) return h[k][v];
  return h[k][v] = getit(p[k - 1][v], k - 1) + getit(v, k - 1);
}
inline int get(int v, int k) {
  if (k < 0) return 0;
  int res = 0;
  for (int i = 20 - 1; i >= 0; --i) {
    if ((k & (1 << i)) > 0) {
      res += getit(v, i);
      k ^= (1 << i);
      v = p[i][v];
    }
  }
  return res;
}
void go(int v = 0) {
  for (const int& v2 : g[v]) {
    go(v2);
    d[v][0] += max(d[v2][0], d[v2][1]);
  }
  for (const int& v2 : g[v]) {
    h[0][v2] = d[v][0] - max(d[v2][0], d[v2][1]);
  }
  for (const auto& t : first[v]) {
    int cost = t.first;
    int v1 = t.second.first;
    int v2 = t.second.second;
    int w = -d[v][0] + get(v1, lvl[v1] - lvl[v]) + get(v2, lvl[v2] - lvl[v]) +
            d[v1][0] + d[v2][0] + cost;
    d[v][1] = max(d[v][1], w);
  }
}
int main() {
  memset(h, -1, sizeof(h));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n - 1; ++i) {
    int t;
    scanf("%d", &t);
    --t;
    g[t].push_back(i + 1);
  }
  dfs();
  for (int i = 0; i < m; ++i) {
    int v1, v2, cost;
    scanf("%d%d%d", &v1, &v2, &cost);
    --v1, --v2;
    int lcav = lca(v1, v2);
    first[lcav].push_back(make_pair(cost, make_pair(v1, v2)));
  }
  go();
  printf("%d\n", max(d[0][0], d[0][1]));
  return 0;
}