#Q72. 「一本通 3.1 练习 5」最小生成树计数
「一本通 3.1 练习 5」最小生成树计数
Description
Original source: JSOI 2008
You are given a simple undirected weighted graph. You are not satisfied with just finding the minimum spanning tree (MST) of this graph but also want to know how many different MSTs exist. (Two MSTs are considered different if they differ by at least one edge.)
Input Format
The first line contains two integers, and , representing the number of nodes and edges in the undirected graph, respectively. The nodes are labeled with integers from to .
The next lines each contain three integers: , , and , indicating that the weight of the edge between nodes and is .
Output Format
Output the number of different MSTs. You only need to output the count modulo .
Sample 1
4 6
1 2 1
1 3 1
1 4 1
2 3 2
2 4 1
3 4 1
8
Data Range and Hints
For all data, , , and .
The data guarantees that there are no self-loops or multiple edges.
Note: There will be no more than edges with the same weight.