码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4408 Minimum Spanning Tree 最小生成树计数

时间:2014-11-03 14:36:06      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   os   java   for   

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 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 above mentioned, appears in the first line of each test case.
【Sample Input】
5 10 12
2 5 3
2 4 2
3 1 3
3 4 2
1 2 3
5 4 3
5 1 3
4 1 1
5 3 3
3 2 3
0 0 0

【Sample Output】

4

【题意】

一张无向图,要求求出其中最小生成树的棵树。
【分析】

 

HDU 4408 Minimum Spanning Tree 最小生成树计数

标签:des   style   blog   io   color   ar   os   java   for   

原文地址:http://www.cnblogs.com/jcf94/p/4071098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!