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;
long long po(long long a, long long b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2) {
      x = x * y;
      x %= 1000000007;
    }
    y = y * y;
    y %= 1000000007;
    b /= 2;
  }
  return x;
}
vector<int> adj[300005];
const int N = 200005, LOGN = 20;
static int dp_lca[LOGN][N], h_lca[N];
static int st[400005], en[400005], ptr = 1;
void dfs0_lca(int cur, int pr = 0) {
  st[cur] = ptr++;
  dp_lca[0][cur] = pr;
  h_lca[cur] = h_lca[pr] + 1;
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] == pr) continue;
    dfs0_lca(adj[cur][i], cur);
  }
  en[cur] = ptr - 1;
}
void build_sparse(int n) {
  dfs0_lca(1);
  for (int i = 1; i < LOGN; i++) {
    for (int j = 1; j <= n; j++) {
      dp_lca[i][j] = dp_lca[i - 1][dp_lca[i - 1][j]];
    }
  }
}
int LCA(int u, int v) {
  if (h_lca[u] < h_lca[v]) {
    swap(u, v);
  }
  for (int i = LOGN - 1; i >= 0; i--) {
    if (dp_lca[i][u] != 0 && h_lca[dp_lca[i][u]] >= h_lca[v]) {
      u = dp_lca[i][u];
    }
  }
  if (u == v) {
    return u;
  }
  for (int i = LOGN - 1; i >= 0; i--) {
    if (dp_lca[i][u] != 0 && dp_lca[i][v] != 0 &&
        dp_lca[i][u] != dp_lca[i][v]) {
      u = dp_lca[i][u];
      v = dp_lca[i][v];
    }
  }
  return dp_lca[0][u];
}
vector<pair<int, pair<int, long long> > > possible[300005];
static long long f[300004], s[300004];
int find(int cur, int delta) {
  for (int i = 19; i >= 0; i--) {
    if ((delta >> i) & 1) {
      cur = dp_lca[i][cur];
    }
  }
  assert(cur >= 1);
  return cur;
}
static long long bit[400005];
long long query(int ind) {
  long long ans = 0;
  while (ind > 0) {
    ans += bit[ind];
    ind -= ind & -ind;
  }
  return ans;
}
void update(int ind, long long delta) {
  while (ind <= 4e5) {
    bit[ind] += delta;
    ind += ind & -ind;
  }
  return;
}
void dfs(int cur, int pr) {
  s[cur] = 0ll;
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] == pr) {
      continue;
    }
    dfs(adj[cur][i], cur);
    s[cur] += f[adj[cur][i]];
  }
  f[cur] = s[cur];
  for (int i = 0; i < possible[cur].size(); i++) {
    int u = possible[cur][i].first;
    int v = possible[cur][i].second.first;
    long long c = possible[cur][i].second.second;
    long long now = s[cur];
    int delta = h_lca[u] - h_lca[cur] - 1;
    if (u != cur) {
      int u1 = find(u, delta);
      now -= f[u1];
      assert(dp_lca[0][u1] == cur);
      now += s[u];
      now += query(st[u]);
    }
    delta = h_lca[v] - h_lca[cur] - 1;
    if (v != cur) {
      int v1 = find(v, delta);
      now -= f[v1];
      assert(dp_lca[0][v1] == cur);
      now += s[v];
      now += query(st[v]);
    }
    now = now + c;
    f[cur] = max(f[cur], now);
  }
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] == pr) {
      continue;
    }
    int ch = adj[cur][i];
    update(st[ch], s[cur] - f[ch]);
    update(en[ch] + 1, -(s[cur] - f[ch]));
  }
  return;
}
int main() {
  if (0) {
    freopen("C:/Users/gold/Desktop/sublime IO/input.txt", "r", stdin);
    freopen("C:/Users/gold/Desktop/sublime IO/output.txt", "w", stdout);
  }
  int T = 1;
  while (T--) {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 2; i <= n; i++) {
      int p;
      scanf("%d", &p);
      adj[p].push_back(i);
      adj[i].push_back(p);
    }
    build_sparse(n);
    for (int i = 0; i < m; i++) {
      int u, v;
      long long c;
      scanf("%d %d %lld", &u, &v, &c);
      int lca = LCA(u, v);
      possible[lca].push_back(make_pair(u, make_pair(v, c)));
    }
    dfs(1, -1);
    printf("%lld\n", f[1]);
  }
  return 0;
}