func_code_string: #include <bits/stdc++.h>   template <typename T>   inline bool chkmin(T &a, T b) {     return b < a ? a = b, true : false;   }   template <typename T>   inline bool chkmax(T &a, T b) {     return b > a ? a = b, true : false;   }   template <class T>   inline T read(T &x) {     int sign = 1;     char c = getchar_unlocked();     for (; !isdigit(c); c = getchar_unlocked())       if (c ==  - ) sign = -1;     for (x = 0; isdigit(c); c = getchar_unlocked()) x = x * 10 + c -  0 ;     return x *= sign;   }   template <class T>   inline void write(T x) {     if (x == 0) {       putchar_unlocked( 0 );       return;     }     if (x < 0) {       putchar_unlocked( - );       x = -x;     }     static char s[20];     int top = 0;     for (; x; x /= 10) s[++top] = x % 10 +  0 ;     while (top) putchar_unlocked(s[top--]);   }   const int maxN = 500 + 1;   const short inf = 0x3f3f;   struct Edge {     int v, next;   } edge[maxN << 1];   int head[maxN];   inline void addedge(int u, int v) {     static int totedge = 0;     edge[++totedge] = (Edge){v, head[u]}, head[u] = totedge;   }   int size[maxN], col[maxN];   long long G[maxN][maxN];   short dp[maxN][maxN][maxN], f[maxN][maxN];   int n, L;   void dfs(int u, int fa) {     size[u] = 0;     for (int e = head[u]; e; e = edge[e].next) {       int v = edge[e].v;       if (v != fa) {         dfs(v, u);         for (int p = 1; p <= n; ++p) {           if (G[u][p] > L) continue;           int tmp[maxN];           std::fill(tmp, tmp + size[u] + size[v] + 1, +inf);           for (int i = 0; i <= size[u]; ++i)             for (int j = 0; j <= size[v]; ++j) {               chkmin(tmp[i + j], dp[u][i][p] + dp[v][j][p]);               chkmin(tmp[i + j], dp[u][i][p] + f[v][j]);             }           for (int i = 0; i <= size[u] + size[v]; ++i) dp[u][i][p] = tmp[i];         }         size[u] += size[v];       }     }     ++size[u];     std::fill(f[u], f[u] + size[u] + 1, +inf);     for (int p = 1; p <= n; ++p) {       dp[u][size[u]][p] = +inf;       if (G[u][p] > L) {         for (int i = 0; i <= size[u]; ++i) dp[u][i][p] = +inf;         continue;       }       for (int i = 0; i < size[u]; ++i)         chkmin(f[u][i + 1], short(dp[u][i][p] + !col[p]));     }   }   int main() {     if (fopen( tmp.in ,  r )) {       freopen( tmp.in ,  r , stdin);       freopen( tmp.out ,  w , stdout);     }     int tot = 0;     read(n), read(L);     for (int i = 1; i <= n; ++i) tot += read(col[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) G[i][j] = i == j ? 0 : 0x3f3f3f3f3f3f3f3fll;     for (int i = 1; i < n; ++i) {       int u, v;       long long w;       read(u), read(v), read(w);       addedge(u, v), addedge(v, u);       chkmin(G[u][v], w), chkmin(G[v][u], w);     }     for (int k = 1; k <= n; ++k)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) chkmin(G[i][j], G[i][k] + G[k][j]);     dfs(1, 0);     short ans = inf;     for (int i = 0; i <= tot; ++i) chkmin(ans, f[1][i]);     write(ans == inf ? -1 : ans), putchar_unlocked(  n );     return 0;   }   