#include <bits/stdc++.h>
using namespace std;
const long long mo = 1000000007;
template <typename _T>
void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
int n, k1, a[205], dp[205][205], dep[205], ans;
int to[205 << 1], nxt[205 << 1];
int head[205], tot;
void addEdge(int u, int v) {
  to[++tot] = v;
  nxt[tot] = head[u];
  head[u] = tot;
}
void dfs(int x, int fa) {
  dp[x][0] = a[x];
  dep[x] = dep[fa] + 1;
  for (int i = head[x]; i; i = nxt[i])
    if (to[i] != fa) dfs(to[i], x);
  for (int i = 0; i < n; i++)
    if (!i)
      for (int j = head[x]; j; j = nxt[j]) {
        if (to[j] != fa) dp[x][i] += dp[to[j]][max(0, k1 - i - 1)];
      }
    else
      for (int j = head[x]; j; j = nxt[j]) {
        if (to[j] == fa) continue;
        int dis = dp[to[j]][i - 1];
        for (int k = head[x]; k; k = nxt[k]) {
          if (to[k] == to[j] || to[k] == fa) continue;
          dis += dp[to[k]][max(i - 1, k1 - i - 1)];
        }
        dp[x][i] = max(dp[x][i], dis);
      }
  for (int i = n - 1; i > 0; i--) dp[x][i - 1] = max(dp[x][i], dp[x][i - 1]);
}
signed main() {
  read(n);
  read(k1);
  k1++;
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    read(u);
    read(v);
    addEdge(u, v);
    addEdge(v, u);
  }
  dfs(1, 0);
  printf("%d\n", dp[1][0]);
  return 0;
}
