#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 13;
const int INF = 1e9;
int n, k;
int a[N];
vector<int> g[N];
int dp[N][N];
int d[N];
int tmp[N];
void dfs(int v, int p = -1) {
  d[v] = 1;
  dp[v][0] = a[v];
  for (auto u : g[v])
    if (u != p) {
      dfs(u, v);
      int nw = max(d[v], d[u] + 1);
      for (int i = 0; i < int(nw); ++i) tmp[i] = -INF;
      for (int i = 0; i < int(d[v]); ++i)
        for (int j = max(0, k - i); j < d[u]; ++j)
          tmp[min(i, j + 1)] = max(tmp[min(i, j + 1)], dp[v][i] + dp[u][j]);
      for (int i = 0; i < int(d[u]); ++i)
        tmp[i + 1] = max(tmp[i + 1], dp[u][i]);
      for (int i = 0; i < int(d[v]); ++i) dp[v][i] = max(dp[v][i], tmp[i]);
      for (int i = d[v]; i < nw; ++i) dp[v][i] = tmp[i];
      d[v] = nw;
      for (int i = d[v] - 1; i > 0; --i)
        dp[v][i - 1] = max(dp[v][i - 1], dp[v][i]);
    }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < int(n); ++i) scanf("%d", &a[i]);
  for (int i = 0; i < int(n - 1); ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v, --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0);
  printf("%d\n", dp[0][0]);
}
