Problem: You are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i.

You are given m queries. The i-th query is given as an integer q_i. In this query you need to calculate the number of pairs of vertices (u, v) (u < v) such that the maximum weight of an edge on a simple path between u and v doesn't exceed q_i.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of vertices in the tree and the number of queries.

Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by three integers u_i, v_i and w_i — the labels of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) and the weight of the edge (1 ≤ w_i ≤ 2 ⋅ 10^5). It is guaranteed that the given edges form a tree.

The last line of the input contains m integers q_1, q_2, ..., q_m (1 ≤ q_i ≤ 2 ⋅ 10^5), where q_i is the maximum weight of an edge in the i-th query.

Output

Print m integers — the answers to the queries. The i-th value should be equal to the number of pairs of vertices (u, v) (u < v) such that the maximum weight of an edge on a simple path between u and v doesn't exceed q_i.

Queries are numbered from 1 to m in the order of the input.

Examples

Input


7 5
1 2 1
3 2 3
2 4 1
4 5 2
5 7 4
3 6 2
5 2 3 4 1


Output


21 7 15 21 3 


Input


1 2
1 2


Output


0 0 


Input


3 3
1 2 1
2 3 2
1 3 2


Output


1 3 3 

Note

The picture shows the tree from the first example: <image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long double eps = 1e-12;
long long int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
long long int n, res = 0, k = 0, h, ans = 0, m;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int x, long long int y) {
  return (x * y) / gcd(x, y);
}
long long int pot(long long int a, long long int b) {
  long long int r = 1;
  while (b) {
    if (b % 2) r = (r * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return r % mod;
}
void pr(long long int a[], long long int n) {
  for (long long int i = 1; i <= n; i++) cout << a[i] << " ";
  cout << '\n';
}
void read(long long int a[], long long int n) {
  for (long long int i = 1; i <= n; i++) cin >> a[i];
}
void yes() { cout << "Yes\n"; }
void no() { cout << "No\n"; }
vector<long long int> v[300015], vnode[300015];
void add_edge(long long int x, long long int y) {
  v[x].push_back(y);
  v[y].push_back(x);
}
string s2, ch = "", s, s1 = "", t;
vector<pair<string, long long int> > vs;
vector<pair<pair<long long int, long long int>, long long int> > vvv, vvv2;
vector<pair<long long int, long long int> > vv[300015], vv2;
long long int dp[300015];
long long int parent[300015], amount[300015];
void make_set(long long int v) {
  parent[v] = v;
  amount[v] = 1;
}
long long int find_set(long long int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(long long int a, long long int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (amount[a] < amount[b]) swap(a, b);
    parent[b] = a;
    amount[a] += amount[b];
  }
}
long long int calc(long long int x) { return (x * (x - 1)) / 2; }
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int i = 0, x = 0, z = 0, y = 0, j = 0, q, mx = 0, mm, idx = 0,
                ok = 0, l = 0, r, negatif = 0, positif = 0;
  set<pair<long long int, long long int> >::iterator itw, ith;
  set<long long int>::iterator it;
  multiset<long long int> mst, mst2;
  cin >> n >> q;
  vector<pair<long long int, pair<long long int, long long int> > > vvv;
  for (i = 1; i <= (long long int)(n - 1); i++) {
    cin >> x >> y >> z;
    vvv.push_back({z, {x, y}});
  }
  for (i = 1; i <= (long long int)(n); i++) make_set(i);
  sort(vvv.rbegin(), vvv.rend());
  vector<pair<long long int, long long int> > queries;
  for (i = 1; i <= (long long int)(q); i++) {
    long long int w;
    cin >> w;
    queries.push_back({w, i});
  }
  sort(queries.begin(), queries.end());
  res = 0;
  for (i = 0; i < queries.size(); i++) {
    idx = queries[i].second;
    long long int w = queries[i].first;
    set<long long int> st;
    if ((long long int)(vvv.size()) > 0)
      for (j = (vvv.size() - 1); j >= 0; j--) {
        long long int wcur = vvv[j].first;
        long long int x = vvv[j].second.first;
        long long int y = vvv[j].second.second;
        if (wcur > w) break;
        x = find_set(x);
        y = find_set(y);
        if (x != y) {
          st.insert(x);
          st.insert(y);
        }
      }
    if (st.size())
      for (it = st.begin(); it != st.end(); it++) {
        res -= calc(amount[find_set(*it)]);
      }
    st.clear();
    vector<long long int> cur;
    while (vvv.size()) {
      long long int wcur = vvv.back().first;
      long long int x = vvv.back().second.first;
      long long int y = vvv.back().second.second;
      if (wcur > w) break;
      vvv.pop_back();
      x = find_set(x);
      y = find_set(y);
      if (x != y) {
        if (st.count(x)) st.erase(x);
        if (st.count(y)) st.erase(y);
        union_sets(x, y);
        cur.push_back(find_set(x));
      }
    }
    if (cur.size())
      for (j = 0; j < cur.size(); j++) st.insert(find_set(cur[j]));
    if (st.size())
      for (it = st.begin(); it != st.end(); it++) {
        res += calc(amount[find_set(*it)]);
      }
    dp[idx] = res;
  }
  for (i = 1; i <= (long long int)(q); i++) cout << dp[i] << " ";
  return 0;
}