Tri-State-Area<May Cir 19>
Practice
4.5 (2 votes)
Data structures
Disjoint data structures
Disjoint set
Medium
Problem
40% Success 594 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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$$.

Input

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 \le n \le 300000$$).

The next $$n-1$$ lines describes the tree. Each of which contain three integers, $$v_i$$, $$u_i$$ and $$w_i$$, meaning that there's and edge connecting vertices $$v_i$$ and $$u_i$$ with weight equal to $$w_i$$ ($$0 \le MAXW, w_i \le 10^9$$).

It's guaranteed that the given graph forms a tree.

Output

Print only one integer, the number of desired graphs modulo $$987654319$$.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
3 votes
Tags:
Data StructuresDSUBasics of Disjoint Data StructuresGraphsMinimum spanning treeDisjoint Data Structures
Points:50
6 votes
Tags:
Dijkstra's AlgorithmMedium
Points:50
7 votes
Tags:
Data StructuresDSUBasics of Disjoint Data StructuresDisjoint Data Structures