#include <bits/stdc++.h>
using namespace std;
long long par[200005], sz[200005];
long long root(long long x) {
  return (x == par[x] ? x : (par[x] = root(par[x])));
}
long long ans = 0;
void join(long long x, long long y) {
  ans -= sz[root(y)] * (sz[root(y)] - 1) / 2;
  ans -= sz[root(x)] * (sz[root(x)] - 1) / 2;
  sz[root(x)] += sz[root(y)];
  par[root(y)] = root(x);
  ans += sz[root(x)] * (sz[root(x)] - 1) / 2;
}
long long res[200005];
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, pair<long long, long long>>> sh;
  for (long long i = 1; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    sh.push_back({z, {x, y}});
  }
  for (long long i = 1; i <= n; i++) sz[i] = 1, par[i] = i;
  sort(sh.begin(), sh.end());
  long long l = 0;
  vector<pair<long long, long long>> qr;
  for (long long i = 0; i < m; i++) {
    long long x;
    cin >> x;
    qr.push_back({x, i});
  }
  sort(qr.begin(), qr.end());
  for (auto &cv : qr) {
    while (l < sh.size() && sh[l].first <= cv.first) {
      join(sh[l].second.first, sh[l].second.second);
      l++;
    }
    res[cv.second] = ans;
  }
  for (long long i = 0; i < m; i++) cout << res[i] << (i == m - 1 ? '\n' : ' ');
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
