Given a weighted tree (T) and an integer MAXW, count the number of weighted graphs whose non-negative edges weight at most MAXW and T is an MST (minimum spanning tree) for that graph. Output the result modulo 987654319.
The first line of input contains two integers n and MAXW, the number of vertices of the aforementioned tree and the maximum allowed weight of an edge respectively (1≤n≤300000).
The next n−1 lines describes the tree. Each of which contain three integers, vi, ui and wi, meaning that there's and edge connecting vertices vi and ui with weight equal to wi (0≤MAXW,wi≤109).
It's guaranteed that the given graph forms a tree.
Print only one integer, the number of desired graphs modulo 987654319.
It can easily be shown that the only other graph edge which isn't present in the tree (2−3) should weight at least 3. So there are 4 graphs in total matching the condition (one of them doesn't contain this edge).