#P6643. Ridiculous Netizens
Ridiculous Netizens
Problem Description
Mr. Bread has a tree $T$ with $n$ vertices, labeled by $1,2,\dots,n$. Each vertex of the tree has a positive integer value $w_i$.
The value of a non-empty tree $T$ is equal to $w_1\times w_2\times\dots\times w_n$. A subtree of $T$ is a connected subgraph of $T$ that is also a tree.
Please write a program to calculate the number of non-empty subtrees of $T$ whose values are not larger than a given number $m$.
Input
The first line of the input contains an integer $T(1\leq T\leq 10)$, denoting the number of test cases.
In each test case, there are two integers $n,m(1\leq n\leq 2000,1\leq m\leq 10^6)$ in the first line, denoting the number of vertices and the upper bound.
In the second line, there are $n$ integers $w_1,w_2,\dots,w_n(1\leq w_i\leq m)$, denoting the value of each vertex.
Each of the following $n-1$ lines contains two integers $u_i,v_i(1\leq u_i,v_i\leq n,u_i\neq v_i)$, denoting an bidirectional edge between vertices $u_i$ and $v_i$.
Output
For each test case, print a single line containing an integer, denoting the number of valid non-empty subtrees. As the answer can be very large, output it modulo $10^9 + 7$.
1
5 6
1 2 1 2 3
1 2
1 3
2 4
2 5
14