#include <bits/stdc++.h>
using namespace std;
double A[600][600];
int n, k, m;
int tot, head[505], nx[505 << 1], there[505 << 1], len[505 << 1];
inline void addedge(int x, int y, int Len) {
  ++tot;
  there[tot] = y;
  nx[tot] = head[x];
  len[tot] = Len;
  head[x] = tot;
}
void dfs(int beg, int u, int dis, int fa) {
  if (dis <= k) {
    A[beg][u] = -1;
    for (int i = head[u]; i; i = nx[i])
      if (there[i] != fa) dfs(beg, there[i], min(dis + len[i], k + 1), u);
  }
}
inline double jdz(double x) { return (x < 0 ? 0 - x : x); }
inline void pivot(int ii, int jj) {
  for (int i = 0; i <= m; ++i)
    if (i != ii && A[i][jj] != 0)
      for (int j = 0; j <= n; ++j)
        if (j != jj) A[i][j] -= A[i][jj] / A[ii][jj] * A[ii][j];
  for (int j = 0; j <= n; ++j)
    if (j != jj) A[ii][j] /= A[ii][jj];
  for (int i = 0; i <= m; ++i)
    if (i != ii) A[i][jj] /= -A[ii][jj];
  A[ii][jj] = 1 / A[ii][jj];
}
double simplex() {
  while (1) {
    int ii = 1;
    for (int i = 1; i <= m; ++i)
      if (A[i][0] < A[ii][0]) ii = i;
    if (A[ii][0] >= 0) break;
    int jj = 1;
    for (int i = 1; i <= n; ++i)
      if (A[ii][i] < A[ii][jj]) jj = i;
    if (A[ii][jj] >= 0) return -1000000000;
    pivot(ii, jj);
  }
  while (1) {
    int ii = 1, jj = 1;
    for (int i = 1; i <= n; ++i)
      if (A[0][i] < A[0][jj]) jj = i;
    if (A[0][jj] >= 0) break;
    for (int i = 1; i <= m; ++i)
      if (A[i][jj] > 0 &&
          (A[ii][jj] <= 0 || A[i][0] / A[i][jj] < A[ii][0] / A[ii][jj]))
        ii = i;
    if (A[ii][jj] <= 0) return 1000000000;
    pivot(ii, jj);
  }
  return A[0][0];
}
int main() {
  int t, Black = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (t == 1)
      Black += 1, A[0][i] = 0;
    else
      A[0][i] = 1;
  }
  int x, y, Len;
  tot = 1;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &Len);
    addedge(x, y, Len);
    addedge(y, x, Len);
  }
  for (int i = 1; i <= n; ++i) {
    dfs(i, i, 0, -1);
    A[i][0] = -1;
  }
  m = n + 1;
  for (int i = 1; i <= n; ++i) A[n + 1][i] = 1;
  A[n + 1][0] = Black;
  double ans = -simplex();
  if (ans > n) ans = -1;
  printf("%d\n", (int)ans);
  return 0;
}
