poj2485 Highways
来源:互联网 发布:数据挖掘外文书籍推荐 编辑:程序博客网 时间:2024/05/16 15:31
Highways
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 32882 Accepted: 14952
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.
Source
POJ Contest,Author:Mathematica@ZSU
题意:裸的最小生成树
题解:只要多记录个树中权值最大的边就可以了
代码如下:
#include<stdio.h>using namespace std;const int MAX = 500 + 10;const int INF = 0x3f3f3f3f;int G[MAX][MAX];int dist[MAX];int addvnew[MAX];int n;int prim(int s){int minimax = -INF;int sum = 0;for(int i = 1; i <= n; ++i){dist[i] = G[s][i];addvnew[i] = 0;}addvnew[s] = 1;for(int i = 1;i <= n ; ++i){if(i != s){int min = INF;int v = -1;for(int j = 1; j <= n; ++j){if(!addvnew[j] && dist[j] < min){min = dist[j];v = j;}}if(v != -1){addvnew[v] = 1;if(dist[v] > minimax)minimax = dist[v];sum += dist[v];for(int j = 1;j <= n; ++j){if(!addvnew[j] && G[v][j] < dist[j]){dist[j] = G[v][j];}}} }}//cout << "minmum sum:" << sum << "\n";return minimax;} int main(){int times;scanf("%d",×);while(times--){scanf("%d",&n);int d;for(int i = 1;i <= n; ++i){for(int j = 1;j <= n; ++j){scanf("%d",&d);G[i][j] = G[j][i] = d;}}printf("%d\n",prim(1));}}
阅读全文
0 0
- POJ2485 Highways
- POJ2485 Highways
- poj2485 Highways
- Highways(POJ2485)
- poj2485 Highways
- poj2485 - Highways
- POJ2485--Highways
- poj2485 Highways
- poj2485 - Highways
- poj2485--Highways
- POJ2485 - Highways
- POJ2485---Highways
- POJ2485 Highways
- Highways||POJ2485
- [POJ2485]Highways
- POJ2485 Highways
- poj2485 Highways
- poj2485-Highways
- php 获取文件扩展名
- 把一个float四舍五入到小数点后2位,4位,或者其它指定位数.
- 欢迎使用CSDN-markdown编辑器
- GNU下Makefile执行顺序
- 51信用卡前端笔试题
- poj2485 Highways
- cin
- hdu2586-How far away ?(最近公共祖先(LCA),离线Tarjan算法)
- Linux rz和sz命令无效
- HDU1166 数状数组
- 程序的内存四区模型
- Java中Date和Calender类的使用方法
- 高效率秘籍
- 云计算学习关键字(待补充...)