#include <bits/stdc++.h>
using namespace std;
int n, k, out[600], basis[600], m, B;
double A[600][600];
struct edge {
  int v, w;
};
vector<edge> G[600];
void addedge(int u, int v, int w) { G[u].push_back((edge){v, w}); }
double fabs(double x) { return x < 0 ? -x : x; }
void orz(int a, int b) {
  for (int i = (0); i <= (m); i++)
    if (i != a && fabs(A[i][b]) > 0)
      for (int j = (0); j <= (n); j++)
        if (j != b) A[i][j] -= A[a][j] * A[i][b] / A[a][b];
  for (int j = (0); j <= (n); j++)
    if (j != b) A[a][j] /= A[a][b];
  for (int i = (0); i <= (m); i++)
    if (i != a) A[i][b] /= -A[a][b];
  A[a][b] = 1 / A[a][b];
}
double simplex() {
  for (;;) {
    int ii = 1, jj = 0;
    for (int i = (1); i <= (m); i++)
      if (A[i][n] < A[ii][n]) ii = i;
    if (A[ii][n] >= 0) break;
    for (int i = 0; i < (n); i++)
      if (A[ii][i] < A[ii][jj]) jj = i;
    if (A[ii][jj] >= 0) return -1e99;
    orz(ii, jj);
  }
  for (;;) {
    int ii = 1, jj = 0;
    for (int j = 0; j < (n); j++)
      if (A[0][j] < A[0][jj]) jj = j;
    if (A[0][jj] >= 0) break;
    for (int i = (1); i <= (m); i++)
      if (A[i][jj] > 0 &&
          (A[ii][jj] <= 0 || A[i][n] / A[i][jj] < A[ii][n] / A[ii][jj]))
        ii = i;
    if (A[ii][jj] <= 0) return 1e99;
    orz(ii, jj);
  }
  return A[0][n];
}
void dfs(int st, int u, int dis, int p) {
  if (dis <= k) {
    A[st + 1][u]--;
    for (int i = 0; i < G[u].size(); i++)
      if (G[u][i].v != p) dfs(st, G[u][i].v, min(G[u][i].w + dis, k + 1), u);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (n); i++)
    scanf("%lf", &A[0][i]), B += A[0][i]--, A[0][i] = -A[0][i];
  for (int i = 0; i < (n - 1); i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    addedge(u, v, w);
    addedge(v, u, w);
  }
  for (int i = 0; i < (n); i++) {
    dfs(i, i, 0, -1);
    A[i + 1][n] = -1;
  }
  for (int i = 0; i < (n); i++) A[n + 1][i] = 1;
  A[n + 1][n] = B;
  m = n + 1;
  double get = -simplex();
  if (get > n)
    puts("-1");
  else
    printf("%d\n", (int)get);
}
