func_code_string: #include <bits/stdc++.h>   using namespace std;   long long a[500006];   long long dp[500006];   long long vis[500006];   vector<long long> v[500006];   long long on;   long long n, d, che;   void dfs(long long root, long long parent) {     vis[root] = 1;     dp[root] = 1;     for (auto it : v[root]) {       if (!vis[it]) {         dfs(it, root);         if (a[it] == che && it < on) {           continue;         }         if (it != parent && che <= a[it] && a[it] <= che + d) {           (dp[root] *= (1 + dp[it])) %= 1000000007;         }       }     }   }   void solve() {     cin >> d >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 0; i < n - 1; i++) {       long long a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       on = i;       for (long long j = 1; j <= n; j++) vis[j] = dp[j] = 0;       che = a[i];       dfs(i, -1);       (ans += dp[i]) %= 1000000007;     }     cout << ans <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }   