You are given a weighted tree T and an integer MAXW . You have to count the number of weighted graphs whose non-negative edges weigh at most MAXW and T is an MST(minimum spanning tree) for that graph. Print the result modulo 987654319.
Input
First line: Two integers n and MAXW denoting the number of vertices of the given tree and the maximum allowed weight of an edge respectively (1<=n<=300000)
Next N-1 lines: Describes the tree, each of which contains three integers,v,u,w , which means that there is an edge connecting the vertices v and u with a weight equal to w (0<=MAXW,w <=10^9)
It is guaranteed that the given graph forms a tree.
Output
Print only one integer, the number of desired graphs modulo 987654319.
I have tried making mst from given tree. While creating mst as I was adding edges I checked it wether it would form a cycle or not. If it will form a cycle then I would find the maximum edge till now i.e current edge. And then multiplying them under modulo m