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 = 200005;
const int LG = 18;
vector<int> adj[MAX];
struct path {
  int u, v, w;
  path(int u, int v, int w) : u(u), v(v), w(w) {}
};
vector<path> pv[MAX];
int par[LG][MAX];
int st[MAX], fi[MAX], d[MAX], cnt;
struct fenwick {
  int fen[MAX];
  void _add(int p, int val) {
    for (; p > 0; p -= p & -p) fen[p] += val;
  }
  int _get(int p) {
    int ans = 0;
    for (p++; p < MAX; p += p & -p) ans += fen[p];
    return ans;
  }
  void add(int l, int r, int val) {
    _add(r, val);
    _add(l, -val);
  }
  void add(int v, int val) { add(st[v], fi[v], val); }
  int get(int v) { return _get(st[v]); }
} f1, f2;
void init(int p, int v) {
  par[0][v] = p;
  for (int i = 1; i < LG; i++) par[i][v] = par[i - 1][par[i - 1][v]];
  st[v] = cnt++;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (u != p) {
      d[u] = d[v] + 1;
      init(v, u);
    }
  }
  fi[v] = cnt;
}
int get_parent(int v, int k) {
  for (int i = 0; i < LG; i++)
    if ((1 << i) & k) v = par[i][v];
  return v;
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  u = get_parent(u, d[u] - d[v]);
  if (u == v) return u;
  for (int i = LG - 1; i >= 0; i--)
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  return par[0][v];
}
int dfs(int p, int v) {
  int ans = 0;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (u == p) continue;
    ans += dfs(v, u);
  }
  for (int i = 0; i < pv[v].size(); i++) {
    path x = pv[v][i];
    int res = x.w;
    res += f1.get(x.u);
    res += f1.get(x.v);
    res -= f1.get(v);
    if (par[0][v] != v) res -= f1.get(par[0][v]);
    res -= f2.get(x.u);
    res -= f2.get(x.v);
    res += f2.get(v);
    if (par[0][v] != v) res -= f2.get(par[0][v]);
    ans = max(ans, res);
  }
  f1.add(par[0][v], ans);
  f2.add(v, ans);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    p--;
    adj[i].push_back(p);
    adj[p].push_back(i);
  }
  init(0, 0);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    pv[lca(u, v)].push_back(path(u, v, w));
  }
  cout << dfs(0, 0) << "\n";
  return 0;
}