#P4208. [JSOI2008] 最小生成树计数
[JSOI2008] 最小生成树计数
Description
You are given a simple undirected weighted graph. You are not satisfied with finding just one minimum spanning tree (MST); instead, you want to know how many different MSTs the graph has. Two MSTs are considered different if they differ by at least one edge. Since the number of different MSTs can be large, you only need to output the count modulo .
Input Format
The first line contains two integers and , where , , representing the number of nodes and edges of the undirected graph. Nodes are numbered from to .
The next lines each contain three integers , indicating that there is an edge between nodes and with weight , where .
It is guaranteed that there are no self-loops or multiple edges. Note: For any fixed weight, there are at most edges with that weight.
Output Format
Output the number of different minimum spanning trees. You only need to output the count modulo .
4 6
1 2 1
1 3 1
1 4 1
2 3 2
2 4 1
3 4 1
8
Hint
Constraints and Conventions
For all testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号