#include <bits/stdc++.h>
using namespace std;
int dp[205][205];
int tmp[205];
vector<int> nei[205];
int n, K;
int w[205];
void dfs(int v, int pa) {
  dp[v][0] = w[v];
  for (int i = 0; i < nei[v].size(); i++) {
    int u = nei[v][i];
    if (u == pa) continue;
    dfs(u, v);
    for (int j = 0; j <= n; j++) tmp[j] = dp[v][j];
    for (int j = 0; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (j + k >= K)
          dp[v][min(j, k)] = max(tmp[j] + dp[u][k - 1], dp[v][min(j, k)]);
      }
    }
    for (int j = n - 1; j >= 0; j--) dp[v][j] = max(dp[v][j], dp[v][j + 1]);
  }
}
int main() {
  cin >> n >> K;
  K++;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    nei[x].push_back(y);
    nei[y].push_back(x);
  }
  dfs(0, -1);
  cout << dp[0][0];
}
