#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int n, k;
int a[210], d[210], c[210], co;
vector<int> g[maxn];
void dfs(int u, int fa) {
  d[u] = d[fa] + 1;
  for (int x : g[u]) {
    if (x == fa) continue;
    dfs(x, u);
  }
}
void bfs(int u, int fa, int d) {
  a[u] -= co;
  for (int x : g[u]) {
    if (x == fa) continue;
    if (d < k) bfs(x, u, d + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[i] = i;
  }
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  sort(c + 1, c + n + 1, [](int x, int y) { return d[x] > d[y]; });
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (a[c[i]] > 0) {
      ans += (co = a[c[i]]);
      bfs(c[i], 0, 0);
    }
  cout << ans << '\n';
  return 0;
}
