#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 100100;
const int MOD = 1000 * 1000 * 1000 + 7;
int n, k;
int A[47];
int R[MAX][1 << 7];
int T[MAX][1 << 7];
int S[MAX];
long long F[MAX];
vector<int> G[MAX];
void dfs(int v, int p)
{
S[v] = 1;
vector<int> V;
for (int i = 0; i < G[v].size(); i++)
{
int to = G[v][i];
if (to == p) continue;
V.push_back(to);
dfs(to, v);
S[v] += S[to];
}
for (int i = 0; i < V.size() + 1; i++)
for (int mask = 0; mask < (1<<k); mask++)
T[i][mask] = 0;
T[0][0] = 1;
for (int i = 0; i < V.size(); i++)
for (int mask = 0; mask < (1<<k); mask++)
{
int m = (1 << k) - 1 - mask;
int t = m;
T[i+1][mask] += T[i][mask];
if (T[i+1][mask] >= MOD) T[i+1][mask] -= MOD;
while (t > 0)
{
T[i+1][mask | t] += 1LL * T[i][mask] * R[V[i]][t] % MOD;
if (T[i+1][mask | t] >= MOD) T[i+1][mask | t] -= MOD;
t = (t-1) & m;
}
}
for (int i = 0; i < (1<<k); i++)
{
R[v][i] += T[V.size()][i];
if (R[v][i] >= MOD) R[v][i] -= MOD;
int s = S[v];
for (int j = 0; j < k; j++)
if (i & (1 << j)) s -= A[j];
for (int j = 0; j < k; j++)
if ((i & (1 << j)) == 0 && A[j] == s)
{
R[v][i | (1 << j)] += T[V.size()][i];
if (R[v][i | (1 << j)] >= MOD) R[v][i | (1 << j)] -= MOD;
}
}
}
long long Pow(long long a, long long b)
{
long long res = 1;
while (b)
if (b % 2 == 0)
{
b /= 2;
a = a * a % MOD;
}
else
{
-- b;
res = res * a % MOD;
}
return res;
}
int main()
{
F[0] = 1;
for (int i = 1; i < MAX; i++)
F[i] = F[i-1] * i % MOD;
cin >> n >> k;
for (int i = 0; i < k; i++)
cin >> A[i];
for (int i = 0; i < n-1; i++)
{
int u, v;
scanf("%d %d", &u, &v);
-- u;
-- v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(0, -1);
long long res = R[0][(1 << k)-1];
sort(A, A+k);
int pos = 0;
while (pos < k)
{
int cnt = 1;
while (pos+cnt < k && A[pos+cnt] == A[pos]) ++ cnt;
res = res * Pow(F[cnt], MOD-2) % MOD;
pos += cnt;
}
cout << res << endl;
return 0;
}