Spanning Tree
Time limit1sMemory limit128 MB
Count the minimum spanning trees of a connected weighted multigraph modulo 1000003, where any weight class has at most 4 edges.
- Level
Hard8 of 10
- Topics
- Minimum spanning tree, Union-find, Combinatorics
- Solved
- No attempts yet
Problem
You are given a connected weighted multigraph. Write a program that finds the number of minimum spanning trees of this graph.
Because it is a multigraph, it may contain loops (edges from a vertex to itself), and there may be several edges between the same pair of vertices.
In the given graph, at most edges share the same weight.
Input
The first line contains the number of vertices and the number of edges . (, ) The vertices are numbered from to .
Each of the next lines contains three integers , , and , separated by spaces. (, ) This means there is an edge of weight connecting vertex and vertex .
Output
On the first line, print the number of minimum spanning trees modulo .