• poj 2485 Highways


    Highways
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 24326   Accepted: 11229

    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. 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 villages. 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 should 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 should output a line contains an integer, which is the length of the longest road to be built such that all the villages are connected, and this value is minimum.

    Sample Input

    1
    
    3
    0 990 692
    990 0 179
    692 179 0

    Sample Output

    692
    

    Hint

    Huge input,scanf is recommended.

    Source

    POJ Contest,Author:Mathematica@ZSU
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <string>
     4 #include <queue>
     5 #include <stack>
     6 #include <iostream>
     7 using namespace std;
     8 #define lengthmax 65537
     9 int map[505][505];
    10 int dis[505];
    11 int main(){
    12     //freopen("D:\INPUT.txt","r",stdin);
    13     int t,n;
    14     scanf("%d",&t);
    15     while(t--){
    16         scanf("%d",&n);
    17         int i,j;
    18         for(i=0;i<n;i++){
    19             dis[i]=lengthmax;
    20             for(j=0;j<n;j++){
    21                 scanf("%d",&map[i][j]);
    22             }
    23         }
    24         int m=1,mink,s=0,min,want=-1;
    25         dis[0]=0;//已经在集合里面
    26         while(m<n){//循环n-1次
    27             min=lengthmax;
    28             for(i=1;i<n;i++){
    29                 if(dis[i]>map[s][i]){//更新
    30                     dis[i]=map[s][i];
    31                 }
    32                 if(dis[i]&&min>dis[i]){
    33                     min=dis[i];
    34                     mink=i;
    35                 }
    36             }
    37             //cout<<mink<<endl;
    38             //cout<<min<<endl;
    39             if(min>want){
    40                 want=min;
    41                 //cout<<want<<endl;
    42             }
    43             dis[mink]=0;
    44             s=mink;
    45             m++;
    46         }
    47         cout<<want<<endl;
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    springboot:快速构建一个springboot项目
    SpringBoot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    springboot添加swagger2组件
    Mysql实现企业级数据库主从复制架构实战
    方案优化:网站实现扫描二维码关注微信公众号,自动登陆网站并获取其信息
    网站实现扫描二维码关注微信公众号,自动登陆网站并获取其信息
    九度OJ 1402 特殊的数 -- 位操作
    九度OJ 1385 重建二叉树
    九度OJ 1386 旋转数组的最小数字 【算法】
    九度OJ 城际公路网 -- 图论
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4644993.html
Copyright © 2020-2023  润新知