#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[205];
int dp[205][205];
int arr[205];
vector<int> g[205];
void dfs(int u, int par) {
  for (int &v : g[u]) {
    if (v == par) continue;
    dfs(v, u);
    memcpy(arr, dp[u], k + 1 << 2);
    for (int i = 0; i <= k; ++i) {
      for (int j = k - i - 1; j <= k; ++j) {
        dp[u][min(i, j + 1)] = max(dp[u][min(i, j + 1)], arr[i] + dp[v][j]);
      }
    }
  }
  dp[u][0] = dp[u][k] + a[u];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cout << fixed << setprecision(12);
  cin >> n >> k, ++k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  int ans = dp[1][0];
  for (int i = 1; i <= k; ++i) ans = max(ans, dp[1][i]);
  cout << ans << endl;
  return 0;
}
