#include <bits/stdc++.h>
using namespace std;
double const eps = 1e-7;
struct LP {
  int ov, ev;
  vector<vector<double> > e;
  void adeq(vector<double> const &v) { e.push_back(v); }
  int bad() {
    for (int i = 1; i < (int)(e.size()); ++i)
      if (e[i][ov] < -eps) {
        for (int j = 0; j < (int)(e[i].size()); ++j)
          if (j != ov && e[i][j] < -eps) return j;
        return -2;
      }
    return -1;
  }
  int getkl() {
    for (int i = 0; i < (int)(e[0].size()); ++i)
      if (i != ov && e[0][i] > eps) return i;
    return -1;
  }
  int getmn(int j) {
    int an = 0;
    double mn = 1e18;
    for (int i = 1; i < (int)(e.size()); ++i)
      if (e[i][j] > eps) {
        double t = e[i][ov] / e[i][j];
        if (t < mn) mn = t, an = i;
      }
    assert(an);
    return an;
  }
  void kl(int j) {
    int i = getmn(j);
    double t = e[i][j];
    for (int k = 0; k < (int)(e[i].size()); ++k) e[i][k] /= t;
    for (int k = 0; k < (int)(e.size()); ++k)
      if (k != i) {
        double z = e[k][j];
        for (int w = 0; w < (int)(e[k].size()); ++w) e[k][w] -= z * e[i][w];
      }
  }
  void pl() {
    ov = e[0].size() - 1, ev = e.size() - 1;
    for (int i = 0; i < (int)(e.size()); ++i) e[i].resize(ov + 1 + ev);
    for (int i = 1; i < (int)(e.size()); ++i) e[i][ov + i] = 1.0;
  }
  pair<double, bool> solve() {
    pl();
    int j;
    while ((j = bad()) >= 0) kl(j);
    if (j == -2) return make_pair(0.0, false);
    while ((j = getkl()) >= 0) kl(j);
    return make_pair(-e[0][ov], true);
  }
  void pr() {
    for (int i = 0; i < (int)(e.size()); ++i) {
      for (int j = 0; j < (int)(e[i].size()); ++j) printf("%10lf ", e[i][j]);
      printf("\n");
    }
    printf("\n");
  }
};
int const N = 500;
vector<pair<int, int> > tr[N + 1];
vector<double> fr[N + 1];
int cl[N + 1], n, x;
void fl(int v, vector<double> &vc, int p = 0, long long dp = 0) {
  if (dp > x) vc[v - 1] = 0.0;
  for (int i = 0; i < (int)(tr[v].size()); ++i) {
    int u = tr[v][i].first, w = tr[v][i].second;
    if (u == p) continue;
    fl(u, vc, v, dp + w);
  }
}
int main() {
  scanf("%d%d", &n, &x);
  for (int i = 1; i < (int)(n + 1); ++i) scanf("%d", cl + i);
  for (int i = 1; i < (int)(n); ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    tr[a].emplace_back(b, w);
    tr[b].emplace_back(a, w);
  }
  for (int i = 1; i < (int)(n + 1); ++i) {
    fr[i] = vector<double>(n + 1, -1.0);
    fl(i, fr[i]);
  }
  LP lp;
  vector<double> tmp(n + 1);
  for (int i = 1; i < (int)(n + 1); ++i) tmp[i - 1] = cl[i] ? 0.0 : -1.0;
  lp.adeq(tmp);
  for (int i = 0; i < (int)(n); ++i) tmp[i] = 1.0;
  int bfr = 0;
  for (int i = 1; i < (int)(n + 1); ++i)
    if (cl[i]) ++bfr;
  tmp[n] = bfr;
  lp.adeq(tmp);
  for (int i = 0; i < (int)(n); ++i) tmp[i] = -1.0;
  tmp[n] = -bfr;
  lp.adeq(tmp);
  for (int i = 1; i < (int)(n + 1); ++i) lp.adeq(fr[i]);
  pair<double, bool> an = lp.solve();
  if (an.second)
    printf("%d\n", (int)(-an.first + 0.5));
  else
    printf("-1\n");
}
