#include <bits/stdc++.h>
using namespace std;
using ldbl = long double;
using ll = long long;
using ivec = vector<int>;
using lvec = vector<ll>;
using lmat = vector<lvec>;
using ldvec = vector<ldbl>;
using ldmat = vector<ldvec>;
const ldbl eps = 1e-9, inf = numeric_limits<ldbl>::infinity();
template <class item_type>
void fill_all(vector<item_type>& v, const item_type value) {
  fill(v.begin(), v.end(), value);
}
class LP_solver : public ldvec {
  const int m, n, p, q, v, w;
  ivec B, N;
  ldmat D;
  inline void Pivot(int r, int s) {
    for (int i = 0; i < v; ++i)
      if (i != r)
        for (int j = 0; j < w; ++j)
          if (j != s) D[i][j] -= D[r][j] * D[i][s] / D[r][s];
    for (int j = 0; j < w; ++j)
      if (j != s) D[r][j] /= D[r][s];
    for (int i = 0; i < v; ++i)
      if (i != r) D[i][s] /= -D[r][s];
    D[r][s] = 1.0 / D[r][s], std::swap(B[r], N[s]);
  }
  bool simplex(int phase) {
    for (int x = phase == 1 ? p : m, s = -1, r = 0; r != -1; s = -1) {
      for (int j = 0; j < q; ++j)
        if (phase != 2 or N[j] != -1)
          if (s == -1 or D[x][j] < D[x][s] or
              (abs(D[x][j] - D[x][s]) < eps and N[j] < N[s]))
            s = j;
      if (D[x][s] < -eps)
        r = -1;
      else
        return true;
      for (int i = 0; i < m; ++i)
        if (D[i][s] > eps)
          if (r == -1 or D[i][q] / D[i][s] < D[r][q] / D[r][s] or
              (abs(D[i][q] * D[r][s] - D[r][q] * D[i][s]) < eps and
               B[i] < B[r]))
            r = i;
      if (r != -1) Pivot(r, s);
    }
    return false;
  }

 public:
  ldbl ans = inf;
  LP_solver(const ldmat& A, const ldvec& b, const ldvec& c)
      : m(b.size()),
        n(c.size()),
        p(m + 1),
        q(n + 1),
        v(p + 1),
        w(q + 1),
        B(m),
        N(q),
        D(v, ldvec(w)) {
    for (int i = 0; i < m; ++i)
      for (int j = 0; j < n; ++j) D[i][j] = A[i][j];
    for (int i = 0; i < m; ++i) B[i] = n + i, D[i][n] = -1, D[i][q] = b[i];
    for (int j = 0; j < n; ++j) N[j] = j, D[m][j] = -c[j];
    N[n] = -1, D[p][n] = 1;
    int r = 0;
    for (int i = 1; i < m; i++)
      if (D[i][q] < D[r][q]) r = i;
    if (D[r][q] < -eps) {
      Pivot(r, n);
      if (!simplex(1) or D[p][q] < -eps) {
        ans = -inf;
        return;
      }
      for (int i = 0; i < m; i++)
        if (B[i] == -1) {
          int s = -1;
          for (int j = 0; j <= n; j++)
            if (s == -1 or D[i][j] < D[i][s] or
                (abs(D[i][j] - D[i][s]) < eps and N[j] < N[s]))
              s = j;
          Pivot(i, s);
        }
    }
    if (!simplex(2)) return;
    resize(n, 0.0);
    for (int i = 0; i < m; i++)
      if (B[i] < n) at(B[i]) = D[i][q];
    ans = D[m][q];
  }
};
int main() {
  int n, x;
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cin >> n >> x;
  ldmat A(n + 2, ldvec(n));
  ldvec B(n + 2, -1), C(n, -1);
  lmat t(n, lvec(n, LLONG_MAX));
  ll ans = -1;
  B[n] = 0;
  for (int color, i = 0; i < n; ++i)
    if (cin >> color, color == 1) B[n]++, C[i] = 0;
  B[n + 1] = -B[n] + eps, B[n] = B[n] + eps;
  for (int i = 0; i < n; ++i) t[i][i] = 0;
  for (int u, v, w, i = 1; i < n; ++i)
    cin >> u >> v >> w, t[--u][--v] = w, t[v][u] = w;
  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        if (t[i][k] != LLONG_MAX and t[k][j] != LLONG_MAX and
            t[i][k] + t[k][j] < t[i][j])
          t[i][j] = t[i][k] + t[k][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) A[i][j] = t[i][j] > x ? 0 : -1;
  fill_all(A[n], ldbl(1.0)), fill_all(A[n + 1], ldbl(-1.0));
  const LP_solver X(A, B, C);
  if (int(X.size()) == n) ans = round(-X.ans);
  cout << ans << endl;
}
