#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e5 + 100;
const int mod = (int)1e9 + 7;
int n, k, ans, dep[220], a[220], b[220];
vector<int> g[220];
void work(int x) {
  int vis[220] =
      {
          0,
      },
      tmp = a[x];
  queue<pair<int, int> > q;
  q.push({x, 0});
  vis[x] = 1;
  while (!q.empty()) {
    int v = q.front().first, dep = q.front().second;
    q.pop();
    vis[v] = 1;
    a[v] -= tmp;
    if (dep != k) {
      for (auto c : g[v])
        if (!vis[c]) q.push({c, dep + 1});
    }
  }
}
void dfs(int x, int fa, int de) {
  dep[x] = de;
  for (auto u : g[x])
    if (u != fa) dfs(u, x, de + 1);
}
int cmp(int a, int b) { return dep[a] > dep[b]; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]), b[i] = i;
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0, 0);
  sort(b + 1, b + 1 + n, cmp);
  for (int i = (1); i <= (n); ++i)
    if (a[b[i]] > 0) ans += a[b[i]], work(b[i]);
  printf("%d\n", ans);
}
