#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const long long INF = 1e9;
const long long MOD = 1000000007;
int n, k;
int arr[203];
vector<vector<int>> ve(203);
vector<int> dfs(int ind, int prev) {
  vector<int> v1(k + 2, 0);
  v1[0] = arr[ind];
  for (auto i : ve[ind]) {
    if (i == prev) continue;
    vector<int> v2;
    v2 = dfs(i, ind);
    vector<int> v3(k + 3, 0);
    for (int i = 1; i <= k + 1; i++) {
      if (v2[i - 1] != 0) {
        for (int j = k + 1 - i; j <= k + 1; j++)
          if (v1[j] != 0) v3[min(i, j)] = max(v3[min(i, j)], v2[i - 1] + v1[j]);
      }
      v3[i] = max(v3[i], v2[i - 1]);
    }
    for (int i = 0; i <= k; i++) v1[i] = max(v1[i], v3[i]);
    for (int i = 0; i <= k; i++)
      for (int j = i + 1; j <= k + 1; j++) v1[i] = max(v1[i], v1[j]);
  }
  return v1;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ve[x].push_back(y);
    ve[y].push_back(x);
  }
  vector<int> v1 = dfs(1, -1);
  int mm = 0;
  for (auto i : v1) mm = max(i, mm);
  cout << mm;
}
