#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int a[1005];
vector<int> G[1005];
int tmp[1005];
int length[1005];
int dp[1005][1005];
void dfs(int u, int f) {
  dp[u][0] = a[u];
  for (auto v : G[u]) {
    if (v == f) continue;
    dfs(v, u);
    int newlength = max(length[u], length[v] + 1);
    for (int i = 0; i <= newlength; ++i) tmp[i] = 0;
    for (int i = 0; i <= length[u]; ++i) {
      for (int j = max(0, k + 1 - i - 1); j <= length[v]; ++j) {
        tmp[min(i, j + 1)] = max(tmp[min(i, j + 1)], dp[u][i] + dp[v][j]);
      }
    }
    for (int i = 0; i <= length[v]; ++i) tmp[i + 1] = max(tmp[i + 1], dp[v][i]);
    for (int i = 0; i <= newlength; ++i) dp[u][i] = max(tmp[i], dp[u][i]);
    length[u] = newlength;
    for (int i = newlength - 1; i >= 0; --i)
      dp[u][i] = max(dp[u][i], dp[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; i < n; ++i) {
    int u;
    int v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  printf("%d\n", dp[1][0]);
  return 0;
}
