#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int parent[N], sz[N];
long long res[N];
vector<pair<int, int> > edges[N];
void make_set(int v) {
  parent[v] = v;
  sz[v] = 1;
}
int find_set(int v) {
  if (parent[v] == v) return v;
  return parent[v] = find_set(parent[v]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) make_set(i);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[w].push_back({u, v});
  }
  for (int i = 1; i < N; ++i) {
    res[i] = res[i - 1];
    for (auto p : edges[i]) {
      int a = p.first, b = p.second;
      a = find_set(a);
      b = find_set(b);
      res[i] -= 1ll * sz[a] * (sz[a] - 1) / 2 + 1ll * sz[b] * (sz[b] - 1) / 2;
      if (sz[a] < sz[b]) swap(a, b);
      parent[b] = a;
      sz[a] += sz[b];
      res[i] += 1ll * sz[a] * (sz[a] - 1) / 2;
    }
  }
  while (m--) {
    int q;
    cin >> q;
    cout << res[q] << ' ';
  }
  return 0;
}
