#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, m, q, par[N], sz[N], cnt;
long long ans[N];
vector<pair<int, pair<int, int> > > edges;
vector<pair<int, int> > v;
map<int, int> mp;
int get(int u) { return par[u] == u ? u : par[u] = get(par[u]); }
void mrg(int u, int v) {
  u = get(u);
  v = get(v);
  if (par[u] == par[v]) return;
  if (rand() & 1) swap(u, v);
  par[v] = u;
  mp[sz[u]]--;
  mp[sz[v]]--;
  if (mp[sz[u]] == 0) mp.erase(sz[u]);
  if (mp[sz[v]] == 0) mp.erase(sz[v]);
  sz[u] += sz[v];
  mp[sz[u]]++;
}
int main() {
  scanf("%d%d", &n, &m);
  mp[1] = n;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    edges.push_back({w, {u, v}});
  }
  sort(edges.begin(), edges.end());
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%d", &x);
    v.push_back({x, i});
  }
  sort(v.begin(), v.end());
  for (auto X : v) {
    int val = X.first;
    int idx = X.second;
    for (; cnt < n - 1; cnt++) {
      if (val >= edges[cnt].first)
        mrg(edges[cnt].second.first, edges[cnt].second.second);
      else
        break;
    }
    long long curr = 0;
    for (auto x : mp) curr += 1LL * x.first * (x.first - 1) / 2 * x.second;
    ans[idx] = curr;
  }
  for (int i = 1; i <= m; i++) printf("%lld ", ans[i]);
}
