#t533. 最短网络
最短网络
Shortest Network
Problem Background
Special for beginners, ^_^
Problem Description
Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet to the town and connect it to all the farms. Of course, he needs your help. John has already arranged a high-speed network line for his own farm, and he wants to share this line with the other farms. To spend the least money, he wants to lay the shortest fiber to connect all the farms. You will be given a list of the connection costs between farms, and you must find the plan that connects all the farms with the shortest total fiber length. The distance between any two farms will not exceed .
Input Format
The first line: the number of farms ().
The following lines contain an matrix, all integers, representing the distance between each pair of farms. Of course, the diagonal will be , because there will be no line from the -th farm to itself.
Output Format
A single output containing the minimum total length of fiber needed to connect every farm.
Sample Input
4
0 4 9 21
4 0 8 17
9 8 0 16
21 17 16 0
Sample Output
28
Constraints
Time limit: 1s; memory limit: 1024 KiB for each test case.