#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, next;
};
node t[404];
int n, k, head[202], dep[202], dp[202][202], maxdep[202], a[202], ans;
void build(int u1, int v1, int tot) {
  t[tot].u = u1;
  t[tot].v = v1;
  t[tot].next = head[u1];
  head[u1] = tot;
}
void dfs1(int fa, int p, int cnt) {
  dep[p] = maxdep[p] = cnt;
  for (int i = head[p]; i; i = t[i].next) {
    if (t[i].v != fa) {
      dfs1(p, t[i].v, cnt + 1);
      maxdep[p] = max(maxdep[p], maxdep[t[i].v]);
    }
  }
}
void dfs2(int fa, int p) {
  dp[p][dep[p]] = a[p];
  for (int i = head[p]; i; i = t[i].next) {
    if (t[i].v != fa) {
      dfs2(p, t[i].v);
      for (int l = dep[t[i].v]; l <= maxdep[t[i].v]; l++) {
        if (l - dep[p] > k)
          dp[p][dep[p]] = max(dp[p][dep[p]], dp[t[i].v][l] + a[p]);
        else
          dp[p][l] = max(dp[p][l], dp[t[i].v][l]);
      }
    }
  }
  for (int i = head[p]; i; i = t[i].next) {
    for (int l = dep[t[i].v]; l <= maxdep[t[i].v]; l++) {
      if (t[i].v != fa) {
        int sum = 0, sum1 = 0;
        for (int j = head[p]; j; j = t[j].next) {
          if (t[j].v != fa && t[i].v != t[j].v) {
            int maxn = 0, maxn1 = 0;
            for (int m = l; m <= maxdep[t[j].v]; m++) {
              if (l - dep[p] + m - dep[p] > k) maxn = max(maxn, dp[t[j].v][m]);
              if (l - dep[p] > k && m - dep[p] > k)
                maxn1 = max(maxn1, dp[t[j].v][m]);
            }
            sum += maxn, sum1 += maxn1;
          }
        }
        dp[p][l] = max(dp[p][l], sum + dp[t[i].v][l]);
        if (sum1)
          dp[p][dep[p]] = max(dp[p][dep[p]], sum1 + dp[t[i].v][l] + a[p]);
      }
    }
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u1, v1;
    cin >> u1 >> v1;
    build(u1, v1, i * 2);
    build(v1, u1, i * 2 + 1);
  }
  dfs1(1, 1, 1);
  dfs2(1, 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
