Minimum Spanning Tree
1092 演算法
題目說明
The ACM kingdom has n cities, numbered from 0 to n − 1. An (unordered) pair (i, j) ∈ {0, 1, . . . , n − 1}² of distinct cities is said to be linkable if we are able to build a road linking i and j. It is guaranteed that if we build a road between i and j for all linkable pairs (i, j) ∈ {0, 1, . . . , n − 1}², then any two distinct cities will be reachable (via one or more roads) from each other. For every linkable pair (i, j) ∈ {0, 1, . . . , n − 1}², denote by ci,j ≥ 0 the cost of building a road between i and j. Mr. Smart wants to build roads with the minimum product of costs subject to every city being reachable from every other city. Please help him.
Input
Each test case begins with n and then the number of linkable pairs. Every linkable pair (i, j) ∈ {0, 1, . . . , n − 1}² is specified by i, j and ci,j , in that order. Furthermore, any two consecutive integers are separated by whitespace character(s). The last test case is “0 0”, which shall not be processed.
Output
Do the following for each test case: Denoting by C the minimum product of costs subject to every city being reachable from every other city, please output the remainder of the division of C by 65537, i.e., C mod 65537.
Technical Specification
- There are at most 10 test cases.
- 2 ≤ n ≤ 500.
- There are at most 25000 linkable pairs.
- For every linkable pair (i, j) ∈ {0, 1, . . . , n − 1}², ci,j ∈ {0, 1, . . . , 999}.
解題思路
according to Kruskal’s algorithm to slove the problem.
參考解法
1 |
|