func_code_string: #include <bits/stdc++.h>   using namespace std;   double inf = 1e+10;   double eps = 1e-10;   inline int sgn(const double& x) { return (x > +eps) - (x < -eps); }   const int MAXN = 500;   const int MAXM = 501;   int n, m;   double A[MAXM + 1][MAXN + 1];   int basis[MAXM + 1], out[MAXN + 1];   void pivot(int a, int b) {     for (int i = 0; i <= m; ++i)       if (i != a && sgn(A[i][b]))         for (int j = 0; j <= n; ++j)           if (j != b) A[i][j] -= A[a][j] * A[i][b] / A[a][b];     for (int i = 0; i <= m; ++i)       if (i != a) A[i][b] /= -A[a][b];     for (int j = 0; j <= n; ++j)       if (j != b) A[a][j] /= A[a][b];     A[a][b] = 1 / A[a][b];     swap(basis[a], out[b]);   }   double simplex() {     for (int j = 0; j < n; ++j) A[0][j] = -A[0][j];     for (int i = 0; i <= m; ++i) basis[i] = -i;     for (int j = 0; j <= n; ++j) out[j] = j;     while (true) {       int a = 1, b = 0;       for (int i = 1; i <= m; ++i)         if (make_pair(A[i][n], basis[i]) < make_pair(A[a][n], basis[a])) a = i;       if (A[a][n] >= 0) break;       for (int j = 0; j < n; ++j)         if (A[a][j] < A[a][b]) b = j;       if (A[a][b] >= 0) return -inf;       pivot(a, b);     }     while (true) {       int a = 1, b = 0;       for (int j = 0; j < n; ++j)         if (A[0][j] < A[0][b] || A[0][j] == A[0][b] && out[j] < out[b]) b = j;       if (A[0][b] >= 0) break;       for (int i = 1; i <= m; ++i)         if (A[i][b] > 0 &&             (A[a][b] <= 0 || make_pair(A[i][n] / A[i][b], basis[i]) <                                  make_pair(A[a][n] / A[a][b], basis[a])))           a = i;       if (A[a][b] <= 0) return +inf;       pivot(a, b);     }     return A[0][n];   }   int d;   vector<int> adj[500];   vector<int> wei[500];   void dfs(double A[], int u, int p, int d) {     if (d >= 0) {       A[u]--;       for (int i = 0; i < ((int((adj[u]).size()))); ++i) {         int v = adj[u][i];         if (v != p) {           dfs(A, v, u, d - wei[u][i]);         }       }     }   }   int main() {     scanf( %d%d , &n, &d);     int ttl = 0;     for (int i = 0; i < (n); ++i) {       int ti;       scanf( %d , &ti), A[0][i] = ti - 1, ttl += ti;     }     for (int i = 0; i < (n - 1); ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w), --u, --v;       adj[u].push_back(v), adj[v].push_back(u);       wei[u].push_back(w), wei[v].push_back(w);     }     A[0][n] = 0;     for (int i = 0; i < (n); ++i) {       dfs(A[i + 1], i, -1, d);       A[i + 1][n] = -1;     }     for (int i = 0; i < (n); ++i) A[n + 1][i] = 1;     A[n + 1][n] = ttl;     m = n + 1;     double get = simplex();     int ans;     if (get == -inf)       ans = -1;     else       ans = -get + 0.5;     printf( %d n , ans);   }   