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;
struct Edge {
  int u, v, w;
  Edge(int u, int v, int w) : u(u), v(v), w(w){};
};
const int MAXN = (int)2e5 + 10;
int n, m;
vector<int> adj[MAXN];
int timer;
int p[MAXN][20];
int h[MAXN];
int x[MAXN], y[MAXN];
vector<Edge> path1[MAXN];
vector<Edge> path2[MAXN];
int dp[MAXN];
int f[MAXN];
struct FenwickTree {
  int ft[MAXN];
  void update(int i, int v) {
    while (i <= n) {
      ft[i] += v;
      i += i & -i;
    }
  }
  int query(int i) {
    int ans = 0;
    while (i) {
      ans += ft[i];
      i -= i & -i;
    }
    return ans;
  }
} ft;
void dfs(int u) {
  x[u] = ++timer;
  for (int i = 1; i < 20; ++i) {
    p[u][i] = p[p[u][i - 1]][i - 1];
  }
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    p[v][0] = u;
    h[v] = h[u] + 1;
    dfs(v);
  }
  y[u] = timer;
}
int get_lca(int u, int v) {
  if (h[u] < h[v]) {
    swap(u, v);
  }
  for (int i = 19; i >= 0; --i) {
    if (h[u] - (1 << i) >= h[v]) {
      u = p[u][i];
    }
  }
  if (u == v) {
    return u;
  }
  for (int i = 19; i >= 0; --i) {
    if (p[u][i] != p[v][i]) {
      u = p[u][i];
      v = p[v][i];
    }
  }
  return p[u][0];
}
int nearest_ancestor(int u, int v) {
  int diff = h[v] - h[u] - 1;
  for (int i = 19; i >= 0; --i) {
    if (diff >= (1 << i)) {
      v = p[v][i];
      diff -= 1 << i;
    }
  }
  return v;
}
void update(int u, int val) {
  ft.update(x[u], val);
  ft.update(y[u] + 1, -val);
}
int query(int u, int v) {
  u = p[u][0];
  return ft.query(x[v]) - ft.query(x[u]) + f[v];
}
void compute(int u) {
  int sum = 0;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    compute(v);
    sum += dp[v];
  }
  dp[u] = sum;
  for (int i = 0; i < (int)path1[u].size(); ++i) {
    int v = path1[u][i].v;
    int w = path1[u][i].w;
    int t = nearest_ancestor(u, v);
    dp[u] = max(dp[u], sum - dp[t] + query(t, v) + w);
  }
  for (int i = 0; i < (int)path2[u].size(); ++i) {
    int x = path2[u][i].u;
    int y = path2[u][i].v;
    int w = path2[u][i].w;
    int tx = nearest_ancestor(u, x);
    int ty = nearest_ancestor(u, y);
    dp[u] = max(dp[u], sum - dp[tx] - dp[ty] + query(tx, x) + query(ty, y) + w);
  }
  f[u] = sum;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    update(v, sum - dp[v]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    adj[p].push_back(i);
  }
  dfs(1);
  for (int i = 1; i <= m; ++i) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    int w = get_lca(u, v);
    if (w == u || w == v) {
      path1[w].push_back(Edge(w, u + v - w, c));
    } else {
      path2[w].push_back(Edge(u, v, c));
    }
  }
  compute(1);
  printf("%d\n", dp[1]);
  return 0;
}