#include <bits/stdc++.h>
using namespace std;
const int N = 204;
int n, k, c[N], f[N][3], d[N][N], ans = 0;
vector<int> a[N];
void dfs(int x, int p) {
  d[x][0] = c[x];
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    if (y != p) {
      dfs(y, x);
    }
  }
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    if (y != p) {
      d[x][0] += d[y][k - 1];
      d[x][k] += d[y][k - 1];
    }
  }
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    if (y != p) {
      for (int j = 0; j < k; j++) {
        int dis = max((k + 1) / 2 - 1, k - j - 2);
        dis = max(dis, j);
        int keep = d[y][j];
        for (int z = 0; z < a[x].size(); z++) {
          int t = a[x][z];
          if (t != p && t != y) {
            keep += d[t][dis];
          }
        }
        d[x][j + 1] = max(d[x][j + 1], keep);
      }
    }
  }
  for (int j = k; j >= 0; j--) {
    d[x][j] = max(d[x][j], d[x][j + 1]);
    ans = max(ans, d[x][j]);
  }
}
int main() {
  cin >> n >> k;
  k++;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans;
}
