#include <bits/stdc++.h>
using namespace std;
int n, x;
int dist[501][501];
bool color[501];
unsigned short num_red;
unsigned short ans[501][501][501], best[501][501], sizes[501];
unsigned short inf = ~0;
vector<unsigned short> edge[501];
void dfs(unsigned short& now, unsigned short& before) {
  for (int i = 0; i < edge[now].size(); i++) {
    unsigned short& next = edge[now][i];
    if (next == before) continue;
    dfs(next, now);
  }
  for (int i = 1; i <= n; i++)
    if (dist[now][i] <= x) {
      sizes[now] = 1;
      ans[now][i][1] = !color[i];
      for (int j = 0; j < edge[now].size(); j++) {
        unsigned short& next = edge[now][j];
        if (next == before) continue;
        int num_node;
        if (num_red < sizes[now] + sizes[next])
          num_node = num_red;
        else
          num_node = sizes[now] + sizes[next];
        for (unsigned short k = num_node;; k--) {
          unsigned short temp = inf;
          int num_node_1 = k - sizes[now];
          if (num_node_1 < 0) num_node_1 = 0;
          int num_node_2 = k;
          if (k > sizes[next]) num_node_2 = sizes[next];
          for (unsigned short j = num_node_1; j <= num_node_2; j++) {
            if (temp > ans[now][i][k - j] + best[next][j])
              temp = ans[now][i][k - j] + best[next][j];
          }
          num_node_1++;
          for (unsigned short j = num_node_1; j <= num_node_2; j++) {
            if (temp > ans[now][i][k - j + 1] + ans[next][i][j] - !color[i])
              temp = ans[now][i][k - j + 1] + ans[next][i][j] - !color[i];
          }
          ans[now][i][k] = temp;
          if (!k) break;
        }
        sizes[now] += sizes[next];
      }
    }
  for (unsigned short i = 1; i <= num_red; i++) {
    best[now][i] = inf;
    for (unsigned short j = 1; j <= n; j++) {
      best[now][i] = min(best[now][i], ans[now][j][i]);
    }
  }
}
int main() {
  num_red = 0;
  memset(ans, 0xff, sizeof ans);
  memset(best, 0xff, sizeof best);
  memset(dist, 0x3f3f, sizeof dist);
  cin >> n >> x;
  unsigned short col;
  for (int i = 1; i <= n; i++) {
    cin >> col;
    num_red += col;
    color[i] = col == 1;
  }
  unsigned short a, b;
  int cost;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> cost;
    edge[a].push_back(b);
    edge[b].push_back(a);
    dist[a][b] = dist[b][a] = cost;
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dist[i][j] = i == j ? 0 : min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  unsigned short start = 1;
  unsigned short before = 0;
  dfs(start, before);
  if (best[1][num_red] == inf)
    cout << -1 << endl;
  else
    cout << best[1][num_red] << endl;
  return 0;
}
