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

Dense Subgraph

Time 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
2 5 0 1 1 1 1 1 1 2 2 3 3 4 4 5 3 2 2 1 3 1 2 1 3
 

Sample Output
13 6
 

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-04-25 17:24:18, Gzip enabled