#include <bits/stdc++.h>
using namespace std;
int a[205], sz[205], n, k;
deque<int> g[205], dp[205];
void dfs(int u, int p) {
  dp[u].push_back(a[u]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != p) {
      dfs(v, u);
      dp[v].push_front(dp[v].front());
      if (dp[v].size() > dp[u].size()) swap(dp[u], dp[v]);
      vector<int> result;
      result.resize(dp[v].size());
      for (int i = 0; i < dp[v].size(); i++) {
        int j = max(k - i + 1, i);
        if (i < dp[u].size() && j < dp[v].size() && j >= 0)
          result[i] = max(result[i], dp[u][i] + dp[v][j]);
        if (i < dp[v].size() && j < dp[u].size() && j >= 0)
          result[i] = max(result[i], dp[u][j] + dp[v][i]);
        result[i] = max(result[i], dp[v][i]);
      }
      int mx = 0;
      for (int i = result.size() - 1; i >= 0; i--) {
        mx = max(mx, result[i]);
        dp[u][i] = max(dp[u][i], mx);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 2; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  printf("%d\n", dp[1][0]);
}
