#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _dbg(char const *s, const T &t) {
  cout << s << "=" << t << endl;
}
template <typename T, typename... TA>
void _dbg(char const *s, const T &t, const TA &...ta) {
  while (*s != ',') cout << *s++;
  cout << "=" << t << ",";
  _dbg(s + 1, ta...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream &print_iterable(ostream &os, T beg, T end) {
  os << '[';
  for (auto it = beg; it != end; ++it) {
    if (it != beg) os << ", ";
    os << *it;
  }
  return os << ']';
}
template <typename T, size_t N>
ostream &operator<<(ostream &os, const array<T, N> &x) {
  return print_iterable(os, x.begin(), x.end());
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &x) {
  return print_iterable(os, x.begin(), x.end());
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &x) {
  return print_iterable(os, x.begin(), x.end());
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &x) {
  return print_iterable(os, x.begin(), x.end());
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &x) {
  return print_iterable(os, x.begin(), x.end());
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &x) {
  return print_iterable(os, x.begin(), x.end());
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const unordered_map<T1, T2> &x) {
  return print_iterable(os, x.begin(), x.end());
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
const int N = 202;
int ar[N];
vector<int> gr[N];
int dp[N][N * 2], n, k;
void Dfs(int cur, int par = 0) {
  vector<int> sum(N + 1);
  for (auto &x : gr[cur]) {
    if (x == par) {
      continue;
    }
    Dfs(x, cur);
    for (int i = 0; i < N; ++i) {
      sum[i] += dp[x][i];
    }
  }
  dp[cur][0] = ar[cur] + sum[k];
  for (int i = 1; i < N; ++i) {
    int other = max(i - 1, k - i);
    for (auto &x : gr[cur]) {
      if (x == par) {
        continue;
      }
      dp[cur][i] = max(dp[cur][i], dp[x][i - 1] + sum[other] - dp[x][other]);
    }
  }
  for (int i = N - 1; i >= 0; --i) {
    dp[cur][i] = max(dp[cur][i], dp[cur][i + 1]);
  }
}
void Solve() {
  int a, b;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> ar[i];
  }
  for (int i = 1; i < n; ++i) {
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  Dfs(1);
  cout << dp[1][0] << endl;
}
int main() {
  Solve();
  return 0;
}
