Highways
来源:互联网 发布:泰安中商网络怎么样 编辑:程序博客网 时间:2024/05/16 16:25
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.
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.
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
130 990 692990 0 179692 179 0
Sample Output
692
Hint
Huge input,scanf is recommended.
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#define INF 9999999999using namespace std;int n,dis[66666];int map[5555][200];bool vis[66666];int s[66666];void prim(){ int i,j,k,pos,v=0; int mm; memset(vis,false,sizeof(vis)); memset(s,0,sizeof(s)); for(i=0; i<n; i++) dis[i]=map[0][i]; vis[0]=true; for(i=0; i<n-1; i++) { mm=INF; for(j=0; j<n; j++) { if(vis[j]==false&&dis[j]<mm) { mm=dis[j]; pos=j; } } vis[pos]=true; s[v++]=mm; for(j=0; j<n; j++) { if(vis[j]==false&&dis[j]>map[j][pos]) dis[j]=map[j][pos]; } } int maxx=s[0]; for(i=1; i<v; i++) { if(maxx<s[i]) maxx=s[i]; } printf("%d\n",maxx);}int main(){ int i,j,t; int cnt,ans; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i<n; i++) for(j=0; j<n; j++) scanf("%d",&map[i][j]);// for(i=0;i<n;i++)// dis[i]=map[0][i];// vis[0]=true; prim(); } return 0;}
0 0
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- Highways
- highways
- Groovy入门基础
- Julia:提高性能的N个点
- 安装xampp后apache不能启动解决方法
- [IOS 开发] iOS中的RunTime机制
- 导出 exl 按照已存在的固定格式
- Highways
- 力所能及之struts国际化il8n
- SDUT 2857 艺术联合会(DP)
- Android 读取SIM卡参数 TelephonyManager类详解
- Codeforces Round #290 (Div. 2) C. Fox And Names
- load()与get()方法的关键区别:
- 图的邻接表存储及DFS,BFS遍历
- Android 5.0 源码编译之后打开模拟器
- ibatis动态sql