Problem 3026 --Ridiculous Netizens

3026: Ridiculous Netizens

"
Time Limit $6$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Mr. Bread has a tree TT with nn vertices, labeled by 1,2,…,n1,2,…,n. Each vertex of the tree has a positive integer value wiwi

The value of a non-empty tree TT is equal to w1×w2×⋯×wnw1×w2×⋯×wn. A subtree of TT is a connected subgraph of TT that is also a tree. 

Please write a program to calculate the number of non-empty subtrees of TT whose values are not larger than a given number mm.
The first line of the input contains an integer T(1≤T≤10)T(1≤T≤10), denoting the number of test cases. 

In each test case, there are two integers n,m(1≤n≤2000,1≤m≤106)n,m(1≤n≤2000,1≤m≤106) in the first line, denoting the number of vertices and the upper bound. 

In the second line, there are nn integers w1,w2,…,wn(1≤wi≤m)w1,w2,…,wn(1≤wi≤m), denoting the value of each vertex. 

Each of the following n−1n−1 lines contains two integers ui,vi(1≤ui,vi≤n,ui≠vi)ui,vi(1≤ui,vi≤n,ui≠vi), denoting an bidirectional edge between vertices uiui and vivi.
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 109+7109+7.
1
5 6
1 2 1 2 3
1 2
1 3
2 4
2 5
14

推荐代码 查看3026 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$1316 $ms] 淡意的温柔 591124 2020-06-06 08:17:49
内存最少[$0 $KB] 淡意的温柔 591124 2020-06-06 08:17:49
第一AC 淡意的温柔 591124 2020-06-06 08:17:49
第一挑战 淡意的温柔 591124 2020-06-06 08:17:49

赛题来源/所属竞赛 2019 Multi-University Training Contest 6 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛