Programming hub is organizing its flagship event Execute 17.1 in the college auditorium.
Execute is a team event which will witness a large participation. To connect everyone’s laptop the members have thought of using a wired LAN network. The network is a tree with switches as the nodes of the tree. Each switch has a breakdown connection frequency after which it stops working.
Unfortunately due to heavy traffic, the system is in an unstable state. To fix this we can break the network and connect the broken switch / laptop directly to the router. “K” is the breakdown frequency of the system exceeding which system stops working.
Being the chief engineer this responsibility falls on your shoulder. You need to find the minimum number of networks formed after breaking the network so that total breakdown frequency of every network existing should be less than or equal to “K”.
Input:
First line of input contains the number of test cases.
First line of input contains the number of elements “N” and breakdown frequency “K”.
Second line of input contains an array of size N which contains the breakdown frequency of switches.
Next (N-1) lines contains two integers A and B which means that switch A is connected to switch B.
Output:
Print the required output.
Constraints:
1<=T<=10
1<=N<=10^5
Max (arr)<= K <= 10^18
1<= arr[i] <= 10^9
1<=A,B<=N
Sample Input:
1
3 3
1 2 3
1 2
1 3
Sample Output:
2
Author - Rishabh Jain
We can split the tree into 2 parts 1-2 and 3 as first part’s frequency would be 3 <= K and second parts is 3 <= K