#include <bits/stdc++.h>
using namespace std;
const int N = 200;
int n, k, a[N + 5], f[N + 2][N + 2], tmp[N + 5];
vector<int> e[N + 5];
void Dfs(int u, int fa) {
  f[u][0] = a[u];
  for (const int &v : e[u]) {
    if (v == fa) continue;
    Dfs(v, u);
    for (int i = 0; i <= n; ++i) tmp[i] = f[u][i];
    for (int i = 0; i <= n; ++i) {
      for (int j = max(0, k - i); j <= n; ++j) {
        tmp[min(i, j + 1)] = max(tmp[min(i, j + 1)], f[u][i] + f[v][j]);
      }
    }
    for (int i = 0; i <= n; ++i) f[u][i] = tmp[i];
  }
  for (int i = n - 1; i >= 0; --i) f[u][i] = max(f[u][i], f[u][i + 1]);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  Dfs(1, 0);
  printf("%d\n", f[1][0]);
  return 0;
}
