#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
using namespace std;
using ll = long long;
const int N = 1000;
int n, k;
ll a[N], f[N][N], res;
vector<int> adj[N];
void dfs(int u, int p) {
  ll tf[N];
  f[u][0] = a[u];
  for (int v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    for (int i = 0; i <= k + 5; ++i) tf[i] = f[v][i];
    for (int i = 0; i <= k; ++i) {
      for (int j = k - i; j <= k + 5; ++j) {
        int x = min(i, j + 1);
        tf[x] = max(tf[x], f[u][i] + f[v][j]);
      }
    }
    for (int i = 0; i <= k + 5; ++i) f[u][i] = tf[i];
  }
  for (int i = 0; i <= k + 5; ++i) res = max(res, f[u][i]);
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  dfs(1, -1);
  cout << res;
  return 0;
}
