当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6643:Ridiculous Netizens

题目描述
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$.
输入解释
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$.
输出解释
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
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6643

最后修改于 2020-10-25T23:33:06+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/6000MS(Java/Others) 524288/524288K(Java/Others)