#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a;
vector<int> used;
vector<vector<int>> g;
vector<vector<int>> dp;
vector<vector<int>> sm;
void calc(int cur) {
  sm[cur][n] = dp[cur][n];
  for (int i = n - 1; i >= 0; i--) {
    sm[cur][i] = max(sm[cur][i + 1], dp[cur][i]);
  }
}
void dfs(int cur) {
  used[cur] = 1;
  vector<int> sons;
  for (auto t : g[cur]) {
    if (!used[t]) {
      dfs(t);
      sons.push_back(t);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int c1 = 0; c1 < (int)sons.size(); c1++) {
      int c = dp[sons[c1]][i - 1];
      for (int c2 = 0; c2 < (int)sons.size(); c2++) {
        c += (c1 != c2) * (sm[sons[c2]][max(i - 1, k - i - 1)]);
      }
      dp[cur][i] = max(dp[cur][i], c);
    }
  }
  dp[cur][0] = a[cur];
  for (int j = 0; j < (int)sons.size(); j++) {
    dp[cur][0] += sm[sons[j]][k - 1];
  }
  calc(cur);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  k++;
  used.resize(n);
  g.resize(n);
  dp.resize(n, vector<int>(n + 1));
  sm.resize(n, vector<int>(n + 1));
  a.resize(n);
  for (auto &t : a) {
    cin >> t;
  }
  for (int i = 0; i + 1 < n; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[0][i]);
  }
  cout << ans << endl;
}
