• poj 2485 Highways


    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
    
    求最小生成树中的最大数
    
    
    
    
    #include<iostream>
    #include <string.h>
    #include<stdio.h>
    using namespace std;
    int p[501][501],x,y,vis[501],i,j;
    int main()
    
    
    
    
    { int n,k,t;
    cin>>t;
    while (t--)
    {cin>>n;
        int max;
    	memset(p,0,sizeof(p));
    
    	for(i=1;i<=n;i++)
    		for(j=1;j<=n;j++)
    			cin>>p[i][j];
    		memset(vis,0,sizeof(vis));
    		vis[1]=1;
    
    		for(i=0;i<n-1;i++)
    		{ max=1000000;
    		for(j=1;j<=n;j++)
    		{if(!vis[j]&&p[1][j]<max)
    		{max=p[1][j];
    		x=j;}
    		}
    		vis[x]=1;
    		for(j=1;j<=n;j++)
    		{if(!vis[j]&&p[1][j]>p[x][j])
    		p[1][j]=p[x][j];
    
    
    		}
    		}
    
    for(k=1;k<=n;k++)
        if(p[1][k]>max)
        max=p[1][k];
    cout<<max<<endl;
    
    }
    return 0;}



     

    Hint

    Huge input,scanf is recommended.
     
     
     
  • 相关阅读:
    百度地图Api 根据两个坐标点计算距离
    Android 6.0 Permission权限与安全机制
    CentOS安装nginx
    CentOS安装mysq
    CentOS安装JDK
    -bash: /root/java/jdk/bin/java: cannot execute binary file
    数据库连接池之_DButils
    数据库连接池之_c3p0
    数据库连接池之_Druid简单使用
    后台管理平台编辑表格
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387796.html
Copyright © 2020-2023  润新知