#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 205;
int n, k, a[maxn];
int dp[maxn][maxn];
vector<int> load[maxn];
void dfs(int s, int pre) {
  dp[s][0] = a[s];
  for (int &e : load[s]) {
    if (e == pre) continue;
    dfs(e, s);
    dp[s][0] += dp[e][k];
  }
  for (int i = 1; i <= k; i++) {
    for (int &e : load[s]) {
      if (e == pre) continue;
      int sum = dp[e][i - 1];
      for (int &u : load[s]) {
        if (u == pre || u == e) continue;
        sum = sum + dp[u][max(i - 1, k - i)];
      }
      dp[s][i] = max(dp[s][i], sum);
    }
  }
  for (int i = k; i >= 1; i--) dp[s][i - 1] = max(dp[s][i - 1], dp[s][i]);
}
int main() {
  int s, e;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    cin >> s >> e;
    load[s].push_back(e);
    load[e].push_back(s);
  }
  dfs(1, -1);
  cout << dp[1][0] << endl;
  return 0;
}
