#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  int solve(vector<pair<int, int>>& edges, vector<int>& weights, int K) {
    int n = weights.size();
    vector<vector<int>> graph(n);
    for (auto& E : edges) {
      int u = E.first, v = E.second;
      graph[u].push_back(v);
      graph[v].push_back(u);
    }
    int rt = 0;
    vector<int> pars(n, -1);
    vector<int> dis(n, 0);
    vector<int> ord;
    ord.push_back(rt);
    for (int i = 0; i < ord.size(); ++i) {
      int u = ord[i];
      for (auto v : graph[u]) {
        if (v == pars[u]) {
          continue;
        }
        pars[v] = u;
        dis[v] = dis[u] + 1;
        ord.push_back(v);
      }
    }
    assert(ord.size() == n);
    reverse(ord.begin(), ord.end());
    vector<vector<int>> dp(n, vector<int>(n + 1, 0));
    vector<int> cur(n + 1, 0);
    vector<int> nxt(n + 1, 0);
    for (auto u : ord) {
      int p = pars[u];
      fill(cur.begin(), cur.end(), 0);
      cur[0] = weights[u];
      for (auto v : graph[u]) {
        if (v == p) {
          continue;
        }
        fill(nxt.begin(), nxt.end(), 0);
        for (int i = 0; i <= n; ++i) {
          for (int j = 0; j <= n; ++j) {
            if (i + j + 1 <= K) {
              continue;
            }
            int h = min(i, j + 1);
            nxt[h] = max(nxt[h], cur[i] + dp[v][j]);
          }
        }
        swap(cur, nxt);
      }
      dp[u] = cur;
    }
    int res = 0;
    for (int i = 0; i <= n; ++i) {
      res = max(res, dp[rt][i]);
    }
    return res;
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int n, k;
  cin >> n >> k;
  vector<int> W(n);
  for (int i = 0; i < n; ++i) {
    cin >> W[i];
  }
  vector<pair<int, int>> edges;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    edges.emplace_back(u, v);
  }
  cout << sol.solve(edges, W, k) << "\n";
  return 0;
}
