#P4208. [JSOI2008] 最小生成树计数

    ID: 3139 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2008并查集各省省选江苏生成树素数判断,质数,筛法高斯消元

[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 3101131011.

Input Format

The first line contains two integers nn and mm, where 1n1001 \le n \le 100, 1m10001 \le m \le 1000, representing the number of nodes and edges of the undirected graph. Nodes are numbered from 11 to nn.

The next mm lines each contain three integers a,b,ca, b, c, indicating that there is an edge between nodes aa and bb with weight cc, where 1c1091 \le c \le 10^9.

It is guaranteed that there are no self-loops or multiple edges. Note: For any fixed weight, there are at most 1010 edges with that weight.

Output Format

Output the number of different minimum spanning trees. You only need to output the count modulo 3101131011.

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, 1n1001 \le n \le 100, 1m10001 \le m \le 1000, 1ci1091 \le c_i \le 10^9.

Translated by ChatGPT 5