#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Vi = vector<int>;
void run();
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(18);
  run();
  return 0;
}
int uplg(int n) { return 32 - __builtin_clz(n); }
int uplg(ll n) { return 64 - __builtin_clzll(n); }
int n, k;
vector<Vi> G;
Vi cost;
vector<Vi> dp;
void dfs(int v, int p) {
  if (p != -1) G[v].erase(find((G[v]).begin(), (G[v]).end(), p));
  for (auto& e : (G[v])) dfs(e, v);
  for (int d = (1); d < (k + 1); d++) {
    int first = d - 1;
    int second = k - first - 1;
    if (second > first) {
      int ysum = 0;
      for (auto& e : (G[v])) ysum += dp[e][second];
      for (auto& e : (G[v])) {
        dp[v][d] = max(dp[v][d], ysum - dp[e][second] + dp[e][first]);
      }
    } else {
      for (auto& e : (G[v])) dp[v][d] += dp[e][first];
    }
  }
  dp[v][0] = cost[v];
  for (auto& e : (G[v])) dp[v][0] += dp[e][k];
  for (int d = k - 1; d >= 0; d--) {
    dp[v][d] = max(dp[v][d], dp[v][d + 1]);
  }
}
void run() {
  cin >> n >> k;
  cost.resize(n);
  for (auto& c : (cost)) cin >> c;
  G.resize(n);
  for (int i = (1); i < (n); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dp.resize(n, Vi(k + 1));
  dfs(0, -1);
  int ans = 0;
  for (auto& d : (dp[0])) ans = max(ans, d);
  cout << ans << endl;
}
