Under construction

Still being built. Things may change

Dense Subgraph

Time limit3sMemory limit512 MB

Summary
Count vertex subsets L of a degree-at-most-5 tree whose beauty, the maximum density over connected subsets of size at least two, is at most x.
Level

Hard10 of 10

Topics
Tree, Binary search, Dynamic programming, Divide and conquer
Solved
No attempts yet

Problem

You are given a tree with nn vertices. Each vertex vv has weight ava_v, and every vertex has degree at most 5.

The density of a subset SS of vertices is

∑v∈Sav∣S∣.\frac{\sum_{v \in S}{a_v}}{|S|}.

Consider a subset LL of the tree vertices. The beauty of LL is the maximum density of a subset SS of LL that contains at least two vertices and induces a connected subgraph, or 0 if no such SS exists.

There are 2n2^n ways to choose LL. How many of them have beauty at most xx? Since the answer can be very large, print it modulo 1 000 000 0071\,000\,000\,007.

Input

The first line contains a single integer TT (1≤T≤301 \le T \le 30), the number of test cases.

The first line of each test case contains two integers nn (2≤n≤35 0002 \le n \le 35\,000) and xx (0≤x≤35 0000 \le x \le 35\,000).

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤35 0000 \le a_i \le 35\,000).

Each of the next n−1n-1 lines contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n), an edge between vertices uu and vv. The graph is guaranteed to be a tree, and each vertex has degree at most 5.

Output

For each test case, print one line with the number of subsets LL whose beauty is at most xx, modulo 1 000 000 0071\,000\,000\,007.

Examples1

  1. Example 1

    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
    
    Expected output
    13
    6