#include <bits/stdc++.h>
using namespace std;
const int MAX = 200 + 9;
int n, k, a[MAX], dp[MAX][MAX];
vector<int> adj[MAX];
void DFS(int v, int par);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> k;
  k++;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    adj[x - 1].push_back(y - 1);
    adj[y - 1].push_back(x - 1);
  }
  DFS(0, -1);
  cout << dp[0][0] << '\n';
  return 0;
}
void DFS(int v, int par) {
  vector<int> child;
  for (auto u : adj[v]) {
    if (u != par) {
      DFS(u, v);
      child.push_back(u);
    }
  }
  for (int i = 1; i <= k; i++) {
    if (2 * i >= k) {
      for (auto u : child) dp[v][i] += dp[u][i - 1];
    } else {
      int j = k - i, MX = 0;
      for (auto u : child) {
        dp[v][i] += dp[u][j - 1];
        MX = max(MX, dp[u][i - 1] - dp[u][j - 1]);
      }
      dp[v][i] += MX;
    }
  }
  dp[v][0] = dp[v][k] + a[v];
  for (int i = k - 1; i >= 0; i--) dp[v][i] = max(dp[v][i], dp[v][i + 1]);
}
