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 INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 400007;
const int MAXL = 21;
struct eT {
  void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; }
  int u, v, last;
} edge[MAXN * 2];
struct neT {
  int u, v, w;
};
class ftT {
 public:
  void upd(int p, int x) {
    for (; p < MAXN; p += p & -p) data[p] += x;
  }
  int sum(int p) {
    int ans = 0;
    for (; p; p ^= p & -p) ans += data[p];
    return ans;
  }
  int query(int l, int r) { return sum(r) - sum(l - 1); }

 private:
  int data[MAXN];
} ft, fs;
int n, m;
int ke, la[MAXN];
int il[MAXN], ir[MAXN], ki;
int lev[MAXN], fa[MAXN], lca[MAXN][MAXL];
vector<neT> vr[MAXN];
int dp[MAXN], ds[MAXN];
neT ie[MAXN];
void init();
void input();
void work();
void dfs1(int now, int nl);
void dfs2(int now);
int getlca(int u, int v);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d", &n, &m);
  ke = 0;
  memset(la, -1, sizeof(la));
  int p;
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &p);
    edge[ke].setd(p, i, la[p]);
    la[p] = ke++;
    fa[i] = p;
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &ie[i].u, &ie[i].v, &ie[i].w);
  }
}
void work() {
  dfs1(1, 1);
  memset(lca, -1, sizeof(lca));
  for (int i = 1; i <= n; ++i) lca[i][0] = fa[i];
  for (int j = 1; j < MAXL; ++j)
    for (int i = 1; i <= n; ++i)
      if (~lca[i][j - 1]) lca[i][j] = lca[lca[i][j - 1]][j - 1];
  for (int i = 1; i <= m; ++i) {
    vr[getlca(ie[i].u, ie[i].v)].push_back(ie[i]);
  }
  dfs2(1);
  printf("%d\n", dp[1]);
}
void dfs1(int now, int nl) {
  lev[now] = nl;
  il[now] = ++ki;
  for (int i = la[now]; ~i; i = edge[i].last) {
    dfs1(edge[i].v, nl + 1);
  }
  ir[now] = ++ki;
}
void dfs2(int now) {
  for (int i = la[now]; ~i; i = edge[i].last) {
    dfs2(edge[i].v);
    ds[now] += dp[edge[i].v];
  }
  fs.upd(il[now], ds[now]);
  fs.upd(ir[now], -ds[now]);
  dp[now] = ds[now];
  int u, v, nv;
  for (auto x : vr[now]) {
    u = x.u, v = x.v;
    nv = fs.query(il[now], il[u]) + fs.query(il[now], il[v]) - ds[now] -
         ft.query(il[now], il[u]) - ft.query(il[now], il[v]);
    dp[now] = (((dp[now]) > (nv + x.w)) ? (dp[now]) : (nv + x.w));
  }
  ft.upd(il[now], dp[now]);
  ft.upd(ir[now], -dp[now]);
}
int getlca(int u, int v) {
  if (lev[u] < lev[v]) swap(u, v);
  int d = lev[u] - lev[v];
  for (int b = 0; d; ++b, d >>= 1)
    if (d & 1) u = lca[u][b];
  if (u == v) return u;
  for (int i = MAXL - 1; i >= 0; --i) {
    if (lca[u][i] ^ lca[v][i]) {
      u = lca[u][i];
      v = lca[v][i];
    }
  }
  return fa[u];
}