#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, k;
int a[N];
vector<int> v[N];
int d[N];
void dfs(int now, int pre, int de = 0) {
  d[now] = de;
  for (auto k : v[now]) {
    if (k == pre) continue;
    dfs(k, now, de + 1);
  }
}
int f[N], cost;
void bfs(int now, int pre, int de = 0) {
  if (de > k) return;
  a[now] -= cost;
  for (auto k : v[now]) {
    if (k == pre) continue;
    bfs(k, now, de + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], f[i] = i;
  for (int i = 1; i < n; i++) {
    int s, t;
    cin >> s >> t;
    v[s].push_back(t);
    v[t].push_back(s);
  }
  dfs(1, 0);
  sort(f + 1, f + 1 + n, [](int l, int r) { return d[l] > d[r]; });
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int now = f[i];
    cost = a[now];
    if (cost <= 0) continue;
    ans += cost;
    bfs(now, 0);
  }
  cout << ans << endl;
  return 0;
}
