Highways (Min Spanning Tree _ floy)
Always writable Highways
| Time Limit:1000 MS |
|
Memory Limit:65536 K |
| Total Submissions:22867 |
|
Accepted:10540 |
Description
The island nation of Flatopia is perfectly flat. unfortunately, Flatopia has no public highways. so the traffic is difficult in Flatopia. the Flatopian government is aware of this problem. they're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system.
Flatopian towns are numbered from 1 to N. each highway connects exactly two towns. all highways follow straight lines. all highways can be used in both directions ctions. highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways.
The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.
Input
The first line of input is an integer T, which tells how many test cases followed.
The first line of each case is an integer N (3 <= N <= 500), which is the number of ages. then come N lines, the I-th of which contains N integers, and the j-th of these N integers is the distance (the distance shocould be an integer within [1, 65536]) between village I and village j. there is an empty line after each test case.
Output
For each test case, you shocould output a line contains an integer, which is the length of the longest road to be built such that all the ages are connected, and this value
Sample Input
130 990 692990 0 179692 179 0
Sample Output
692
In fact, it is to find the maximum path in the minimal spanning tree;
The first line T refers to several sets of test data, followed by several villages, and the next n refers to the distance from 1 to n to each village, for example (0,990,692) the distance between village 1 and village 1 is 0, the distance between village 1 is 990, and the distance from village 3 is 692.
#include
#include
#include
#include
#include using namespace std;#define inf 0x3f3f3fint map[505][505];int dis[505];int vis[505];int n;void prim(){ int i,j,k; int sum=0; int max=-1; int min; memset(vis,0,sizeof(vis)); for(i=1; i<=n; i++) dis[i]=map[1][i]; vis[1]=1; for(i=1; i