#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210, INF = 1e9;
int n, k, w[MAXN], u, v, ans;
vector<int> e[MAXN];
struct State {
  deque<int> data;
  int sz;
  void resize(int sz) {
    this->sz = sz;
    data.resize(sz + 1);
  }
  void extend() {
    sz++;
    data.insert(data.begin(), data.front());
  }
} f[MAXN];
void Merge(State& parent, State& child) {
  if (parent.sz < child.sz) swap(parent, child);
  deque<int> tmp = child.data;
  for (long long j = (0); j <= (child.sz); j++) {
    int lim = (k - j + 1 > j ? k - j + 1 : j);
    if (lim <= child.sz)
      tmp[j] = (tmp[j] > parent.data[j] + child.data[lim]
                    ? tmp[j]
                    : parent.data[j] + child.data[lim]);
    if (lim <= parent.sz)
      tmp[j] = (tmp[j] > parent.data[lim] + child.data[j]
                    ? tmp[j]
                    : parent.data[lim] + child.data[j]);
  }
  int suf = 0;
  for (long long j = (child.sz); j >= (0); j--) {
    suf = (suf > tmp[j] ? suf : tmp[j]);
    parent.data[j] = (parent.data[j] > suf ? parent.data[j] : suf);
  }
}
void dp(int u, int fa) {
  f[u].resize(1);
  f[u].data[0] = w[u];
  for (vector<int>::iterator it = e[u].begin(); it != e[u].end(); it++) {
    int v = *it;
    if (v == fa) continue;
    dp(v, u);
    f[v].extend();
    Merge(f[u], f[v]);
  }
}
int main() {
  cin >> n >> k;
  for (long long i = (1); i <= (n); i++) cin >> w[i];
  for (long long i = (1); i <= (n - 1); i++) {
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dp(1, 0);
  cout << f[1].data[0];
  return 0;
}
