F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Ridiculous Netizens

Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 428    Accepted Submission(s): 153


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$.
 

Sample Input
1 5 6 1 2 1 2 3 1 2 1 3 2 4 2 5
 

Sample Output
14
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-03-28 23:41:55, Gzip enabled