#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using uint = unsigned int;
template <typename T>
inline void read(T& x) {
  x = 0;
  long long f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c & 15);
  x *= f;
}
template <typename T>
inline void print(T x) {
  if (!x) {
    putchar('0');
    return;
  }
  static long long st[105];
  if (x < 0) putchar('-'), x = -x;
  long long tp = 0;
  while (x) st[++tp] = x % 10, x /= 10;
  while (tp) putchar(st[tp--] + '0');
}
template <typename T>
inline void print(T x, char c) {
  print(x);
  putchar(c);
}
template <typename T, typename... Args>
inline void read(T& x, Args&... args) {
  read(x);
  read(args...);
}
template <typename T>
inline void sort(vector<T>& v) {
  sort(v.begin(), v.end());
  return;
}
template <typename T>
inline void unique(vector<T>& v) {
  sort(v);
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <typename T>
inline void cmax(T& x, T y) {
  if (x < y) x = y;
  return;
}
template <typename T>
inline void cmin(T& x, T y) {
  if (x > y) x = y;
  return;
}
const long long Mod = LLONG_MAX;
inline long long QP(long long x, long long y) {
  long long ans = 1;
  for (; y; y >>= 1, x = (x * x) % Mod)
    if (y & 1) ans = (ans * x) % Mod;
  return ans;
}
template <typename T>
inline T gcd(T x, T y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
template <typename T>
inline T lcm(T x, T y) {
  return x * y / gcd(x, y);
}
template <typename T>
inline void mul(T& x, T y) {
  x = 1LL * x * y;
  if (x >= Mod) x %= Mod;
}
template <typename T>
inline void add(T& x, T y) {
  if ((x += y) >= Mod) x -= Mod;
}
template <typename T>
inline void sub(T& x, T y) {
  if ((x -= y) < 0) x += Mod;
}
long long n, k;
const long long N = 400 + 10;
long long val[N];
vector<long long> G[N];
inline void Add(long long u, long long v) { G[u].push_back(v); }
vector<long long> dp[N];
inline vector<long long> Copy(vector<long long> v) {
  vector<long long> C;
  C.push_back(0);
  for (auto x : v) C.push_back(x);
  return C;
}
inline vector<long long> Merge(vector<long long> x, vector<long long> y) {
  vector<long long> ans;
  ans.resize(N);
  for (register long long i = 0; i < x.size(); i++)
    for (register long long j = 0; j < y.size(); j++)
      if (i + j > k) cmax(ans[min(i, j)], x[i] + y[j]);
  return ans;
}
inline void Dfs(long long u, long long fa) {
  dp[u][0] = val[u];
  for (auto v : G[u]) {
    if (v == fa) continue;
    Dfs(v, u);
    dp[u] = Merge(dp[u], Copy(dp[v]));
  }
}
signed main() {
  read(n);
  read(k);
  for (register long long i = 1; i <= n; i++) read(val[i]);
  for (register long long i = 1; i <= n; i++) dp[i].resize(N);
  for (register long long i = 1; i <= n - 1; i++) {
    long long u, v;
    read(u, v);
    Add(u, v);
    Add(v, u);
  }
  Dfs(1, 0);
  long long mx = 0;
  for (auto x : dp[1]) cmax(mx, x);
  print(mx, '\n');
  return 0;
}
