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>
int32_t* tin;
int32_t* tout;
int32_t timer_;
int32_t* depths;
int32_t* parents;
void dfs(int32_t vertex, int32_t parent, std::vector<int32_t>* tree,
         int32_t depth) {
  tin[vertex] = timer_++;
  depths[vertex] = depth;
  parents[vertex] = parent;
  for (int32_t i = 0; i < tree[vertex].size(); i++)
    dfs(tree[vertex][i], vertex, tree, depth + 1);
  tout[vertex] = timer_;
}
bool is_ancestor(int32_t v1, int32_t v2) {
  return tin[v1] <= tin[v2] && tout[v1] >= tout[v2];
}
int32_t** ancestors;
void build_ancestors(int32_t vertex, int32_t parent,
                     std::vector<int32_t>* children) {
  ancestors[vertex] = new int32_t[19];
  ancestors[vertex][0] = vertex;
  ancestors[vertex][1] = parent;
  for (int32_t i = 2; i < 19; i++)
    if (ancestors[vertex][i - 1] == -1)
      ancestors[vertex][i] = -1;
    else
      ancestors[vertex][i] = ancestors[ancestors[vertex][i - 1]][i - 1];
  for (int32_t i = 0; i < children[vertex].size(); i++)
    build_ancestors(children[vertex][i], vertex, children);
}
int32_t lca(int32_t v1, int32_t v2) {
  if (is_ancestor(v1, v2)) return v1;
  if (is_ancestor(v2, v1)) return v2;
  int32_t cur = v1;
  for (int32_t i = 18; i >= 0; i--)
    if (ancestors[cur][i] != -1 && !is_ancestor(ancestors[cur][i], v2))
      cur = ancestors[cur][i];
  return ancestors[cur][1];
}
int32_t kth_ancestor(int32_t v, int32_t k) {
  int32_t res = v;
  for (int32_t i = 17; i >= 0; i--)
    if (k & (1 << i)) res = ancestors[res][i + 1];
  return res;
}
struct Path {
  int32_t v1, v2;
  int32_t cost;
  Path(int32_t v1_, int32_t v2_, int32_t cost_)
      : v1(v1_), v2(v2_), cost(cost_) {}
};
class Segtree {
 private:
  int64_t* data;
  int64_t* lazy;
  int32_t n;
  void propagate(int32_t node) {
    lazy[node * 2 + 1] += lazy[node];
    data[node * 2 + 1] += lazy[node];
    lazy[node * 2 + 2] += lazy[node];
    data[node * 2 + 2] += lazy[node];
    lazy[node] = 0;
  }
  int64_t get(int32_t node, int32_t left, int32_t right, int32_t index) {
    if (right - left == 1) return data[node];
    int32_t m = (left + right) / 2;
    propagate(node);
    if (index >= m) return get(node * 2 + 2, m, right, index);
    return get(node * 2 + 1, left, m, index);
  }
  void add(int32_t node, int32_t left, int32_t right, int32_t query_left,
           int32_t query_right, int64_t param) {
    if (left >= query_right || right <= query_left) return;
    if (left >= query_left && right <= query_right) {
      lazy[node] += param;
      data[node] += param;
      return;
    }
    int32_t m = (left + right) / 2;
    propagate(node);
    add(node * 2 + 1, left, m, query_left, query_right, param);
    add(node * 2 + 2, m, right, query_left, query_right, param);
  }

 public:
  Segtree() {}
  Segtree(int32_t size_) : n(size_) {
    data = new int64_t[4 * n];
    lazy = new int64_t[4 * n];
    for (int32_t i = 0; i < 4 * n; i++) {
      data[i] = 0;
      lazy[i] = 0;
    }
  }
  int64_t get(int32_t index) { return get(0, 0, n, index); }
  void add(int32_t left, int32_t right, int64_t param) {
    add(0, 0, n, left, right, param);
  }
};
Segtree segtree_child_sums;
Segtree segtree_sums;
int64_t get_vertical(int32_t bottom, int32_t top, int64_t* dp) {
  int64_t res = segtree_child_sums.get(tin[bottom]);
  if (parents[top] != -1) res -= segtree_child_sums.get(tin[parents[top]]);
  int64_t reduction = segtree_sums.get(tin[bottom]);
  if (parents[top] != -1) reduction -= segtree_sums.get(tin[parents[top]]);
  reduction -= dp[top];
  return res - reduction;
}
void dfs_ans(int32_t vertex, std::vector<int32_t>* tree,
             std::vector<Path>* paths_per_lca, int64_t* dp) {
  for (int32_t i = 0; i < tree[vertex].size(); i++)
    dfs_ans(tree[vertex][i], tree, paths_per_lca, dp);
  int64_t child_sum = 0;
  for (int32_t i = 0; i < tree[vertex].size(); i++)
    child_sum += dp[tree[vertex][i]];
  dp[vertex] = child_sum;
  for (int32_t i = 0; i < paths_per_lca[vertex].size(); i++) {
    int64_t candidate = paths_per_lca[vertex][i].cost + child_sum;
    if (paths_per_lca[vertex][i].v1 != vertex) {
      int32_t prev_v1 = kth_ancestor(
          paths_per_lca[vertex][i].v1,
          depths[paths_per_lca[vertex][i].v1] - depths[vertex] - 1);
      candidate -= dp[prev_v1];
      candidate += get_vertical(paths_per_lca[vertex][i].v1, prev_v1, dp);
    }
    if (paths_per_lca[vertex][i].v2 != vertex) {
      int32_t prev_v2 = kth_ancestor(
          paths_per_lca[vertex][i].v2,
          depths[paths_per_lca[vertex][i].v2] - depths[vertex] - 1);
      candidate -= dp[prev_v2];
      candidate += get_vertical(paths_per_lca[vertex][i].v2, prev_v2, dp);
    }
    dp[vertex] = std::max(dp[vertex], candidate);
  }
  segtree_sums.add(tin[vertex], tout[vertex], dp[vertex]);
  segtree_child_sums.add(tin[vertex], tout[vertex], child_sum);
}
int main() {
  int32_t n, m;
  std::cin >> n >> m;
  std::vector<int32_t>* children = new std::vector<int32_t>[n];
  for (int32_t i = 1; i < n; i++) {
    int32_t parent;
    std::cin >> parent;
    parent--;
    children[parent].push_back(i);
  }
  tin = new int32_t[n];
  tout = new int32_t[n];
  depths = new int32_t[n];
  parents = new int32_t[n];
  dfs(0, -1, children, 0);
  ancestors = new int32_t*[n];
  build_ancestors(0, -1, children);
  std::vector<Path>* paths_per_lca = new std::vector<Path>[n];
  for (int32_t i = 0; i < m; i++) {
    int32_t v1, v2, cost;
    std::cin >> v1 >> v2 >> cost;
    v1--;
    v2--;
    int32_t real1 = v1, real2 = v2;
    int32_t lca_ = lca(real1, real2);
    paths_per_lca[lca_].emplace_back(real1, real2, cost);
  }
  segtree_child_sums = Segtree(n);
  segtree_sums = Segtree(n);
  int64_t* dp = new int64_t[n];
  dfs_ans(0, children, paths_per_lca, dp);
  std::cout << dp[0];
}