#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, s, t;
int co[501], si[501], L[501], R[501];
long long dis[501][501];
short f[501][501][501], g[501][501];
vector<int> zi[501];
vector<pair<int, int> > a[501];
void sou(int x, int y, int id) {
  int i;
  for (i = 0; i < a[x].size(); i++) {
    pair<int, int> A = a[x][i];
    if (A.first == y) continue;
    dis[id][A.first] = dis[id][x] + A.second;
    sou(A.first, x, id);
  }
}
int Cnt;
void Dfs(int x, int y) {
  int i, j, k, u, r;
  zi[x].push_back(x);
  for (i = 0; i < a[x].size(); i++) {
    pair<int, int> A = a[x][i];
    if (A.first == y) continue;
    Dfs(A.first, x);
    for (j = 0; j < zi[A.first].size(); j++) zi[x].push_back(zi[A.first][j]);
  }
  for (j = 1; j <= n; j++) {
    if (dis[x][j] > m) continue;
    si[x] = 1;
    f[x][j][j == x] = j == x && !co[x];
    for (i = 0; i < a[x].size(); i++) {
      pair<int, int> A = a[x][i];
      int w = A.first;
      if (w == y) continue;
      int h[501];
      memset(h, 120, sizeof(h));
      int t = 0;
      for (u = si[x]; u >= 0; u--)
        for (r = si[w]; r >= 0; r--) {
          Cnt++;
          t++;
          short zhi = f[w][j][r];
          if (dis[j][w] > dis[j][x]) zhi = min(zhi, g[w][r]);
          if (zhi < 501) h[u + r] = min(h[u + r], f[x][j][u] + zhi);
        }
      si[x] += si[w];
      for (k = 0; k <= si[x]; k++) f[x][j][k] = h[k];
    }
  }
  for (j = 0; j < zi[x].size(); j++) {
    int A = zi[x][j];
    for (i = 0; i <= si[x]; i++) g[x][i] = min(g[x][i], f[x][A][i]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &co[i]), s += co[i];
  for (i = 1; i <= n - 1; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    a[x].push_back(make_pair(y, z));
    a[y].push_back(make_pair(x, z));
  }
  for (i = 1; i <= n; i++) sou(i, 0, i);
  memset(f, 120, sizeof(f));
  memset(g, 120, sizeof(g));
  Dfs(1, 0);
  short an = 501;
  for (i = 1; i <= n; i++)
    for (j = 0; j <= s; j++) an = min(an, f[1][i][j]);
  printf("%d\n", an == 501 ? -1 : an);
  return 0;
}
