Highways
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 24326 |
|
Accepted: 11229 |
Description
The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia have no public highways. So the traffic are difficult in Flatopia. The Flatopian government is aware of this problem. They ' re planning to build some highways so it'll be possible to drive between any pair of towns without leaving the Highway System.
Flatopian towns is numbered from 1 to N. Each highway connects exactly and towns. All highways follow straight lines. All highways can is used in both directions. Highways can freely cross all other, but a driver can only switch between highways at a town that's located at the end O F 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 are highway-reachable from every the other town.
Input
The first line of input is a integer T, which tells how many test cases followed.
The first line of all case was an integer n (3 <= n <=), which is the number of villages. Then come n lines, the i-th of which contains n integers, and the j-th of these n integers are the distance (the distance s Hould is an integer within [1, 65536]) between village I and village J. There is a empty line after all test case.
Output
For each test case, you should output a line contains an integer, which was the length of the longest road to be built such That all the villages was connected, and this value is minimum.
Sample Input
130 990 692990 0 179692 179 0
Sample Output
692
Hint
Huge input,scanf is recommended.
Source
POJ Contest,author:[email protected]
1#include <cstdio>2#include <cstring>3#include <string>4#include <queue>5#include <stack>6#include <iostream>7 using namespacestd;8 #defineLengthmax 655379 intmap[505][30s];Ten intdis[505]; One intMain () { A //freopen ("D:\\input.txt", "R", stdin); - intT,n; -scanf"%d",&t); the while(t--){ -scanf"%d",&n); - inti,j; - for(i=0; i<n;i++){ +dis[i]=Lengthmax; - for(j=0; j<n;j++){ +scanf"%d",&map[i][j]); A } at } - intm=1, mink,s=0, min,want=-1; -dis[0]=0;//It 's already inside the collection . - while(m<n) {//Cycle n-1 Times -min=Lengthmax; - for(i=1; i<n;i++){ in if(Dis[i]>map[s][i]) {//Update -dis[i]=Map[s][i]; to } + if(dis[i]&&min>Dis[i]) { -min=Dis[i]; themink=i; * } $ }Panax Notoginseng //cout<<mink<<endl; - //cout<<min<<endl; the if(min>want) { +Want=min; A //cout<<want<<endl; the } +dis[mink]=0; -s=Mink; $m++; $ } -cout<<want<<Endl; - } the return 0; -}
POJ 2485 Highways