Minimum Spanning Tree count of HDU 4408 Minimum Spanning Tree

Source: Internet
Author: User
Minimum Spanning Tree

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)

[Problem description] XXX is very interested in algorithm. after learning the prim algorithm and Kruskal algorithm of Minimum Spanning Tree, xxx finds that there might be multiple solutions. given an undirected weighted graph with n (1 <= n <= 100) vertexes and M (0 <= m <= 1000) edges, he wants to know the number of minimum spanning trees in the graph. [input] There are no more than 15 cases. the input ends by 0 0. for each case, the first line begins with three integers --- the above mentioned n, m, and P. the meaning of P will be explained later. each the following M lines contains three integers U, V, W (1 <= W <= 10 ), which describes that there is an edge weighted W between vertex u and vertex v (all vertex are numbered for 1 to n ). it is guaranteed that there are no multiple edges and no loops in the graph. [Output] for each test case, output a single integer in one line representing the number of different minimum spanning trees in the graph. the answer may be quite large. you just need to calculate the remainder of the answer when divided by P (1 <= P <= 1000000000 ). P is abve mentioned, appears in the first line of each test case. [sample input]
5 10 122 5 32 4 23 1 33 4 21 2 35 4 35 1 34 1 15 3 33 2 30 0 0

[Sample output]

4

Question]

For an undirected graph, the Minimum Spanning Tree is required.
[Analysis]

 

Minimum Spanning Tree count of HDU 4408 Minimum Spanning Tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.