|
||||||||||
Dense SubgraphTime Limit: 6000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 57 Accepted Submission(s): 23 Problem Description You have a tree on $n$ vertices, and each vertex has a weight $a_v$ and a degree at most $5$. Let's call the density of a subset of vertices $S$ value $\frac{\sum_{v \in S} a_v}{|S|}$, and call the beauty of the tree with some vertices turned off the maximum value of the density of a subset of at least two turned on vertices with connected induced subgraph, or $0$ if no such subset exists. Now you need to calculate the number of ways to choose such a set of turned off vertices among $2^n$ ways that the beauty of the tree is no larger than $x$, modulo $1\,000\,000\,007$. Input The input contains several test cases, and the first line contains a single integer $T~(1 \le T \le 30)$, the number of test cases. The first line of each test case contains two integers $n~(2 \leq n \leq 35\,000)$ and $x~(0 \leq x \leq 35\,000)$, the number of vertices of a tree and the constraint on the beauty. The next line contains $n$ integers $a_1, a_2, \ldots, a_n~(0 \leq a_i \leq 35\,000)$, the weights of the tree vertices. Each of the next $n-1$ lines contains two integers $u$ and $v~(1 \leq u, v \leq n)$, describing an edge connecting vertices $u$ and $v$ in the tree. It is guaranteed that each vertex of a tree has a degree at most $5$. Output For each test case, output a line containing a single integer, indicating the number of ways to choose such a set of turned off vertices among $2^n$ ways that the beauty of the tree is no larger than $x$, modulo $1\,000\,000\,007$. Sample Input
Sample Output
Source | ||||||||||
|