#Q72. 「一本通 3.1 练习 5」最小生成树计数

    ID: 2154 Type: Default 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>数学矩阵树定理最小生成树JSOI早于 2010一本通提高

「一本通 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, nn and mm, representing the number of nodes and edges in the undirected graph, respectively. The nodes are labeled with integers from 11 to nn.
The next mm lines each contain three integers: aa, bb, and cc, indicating that the weight of the edge between nodes aa and bb is cc.

Output Format

Output the number of different MSTs. You only need to output the count modulo 3101131011.

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

The data guarantees that there are no self-loops or multiple edges.

Note: There will be no more than 1010 edges with the same weight.