poj2485 Highways
Description
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 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
Sample Input
1 3
0 990 692
990 0 179
692 179 0
Sample Output
692
Hint
Source
#include<stdio.h>
#include<string.h>
int map[505][505];
int dis[505],vis[505];
int n;
int prim(int u){
int tmax=0;
for(int i=1;i<=n;i++){
dis[i]=map[u][i];
}
vis[u]=1;
for(int k=1;k<n;k++){
int tmin=999999999;
int temp;
for(int j=1;j<=n;j++){
if(dis[j]<tmin&&!vis[j]){
tmin=dis[j];
temp=j;
}
}
vis[temp]=1;
if(tmin>tmax)
tmax=tmin;
for(int i=1;i<=n;i++){
if(dis[i]>map[temp][i]&&!vis[i])
dis[i]=map[temp][i];
}
}
return tmax;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
memset(vis,0,sizeof(vis));
memset(dis,0,sizeof(dis));
memset(map,0,sizeof(map));
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&map[i][j]);
}
}
printf("%d\n",prim(1));
printf("\n");
}
return 0;
}
poj2485 Highways的更多相关文章
- POJ2485——Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- POJ2485:Highways(模板题)
http://poj.org/problem?id=2485 Description The island nation of Flatopia is perfectly flat. Unfortun ...
- POJ2485 Highways 【MST】
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22842 Accepted: 10525 Descri ...
- POJ2485 Highways(最小生成树)
题目链接. 分析: 比POJ2253要简单些. AC代码: #include <iostream> #include <cstdio> #include <cstring ...
- 最小生成树Prim poj1258 poj2485 poj1789
poj:1258 Agri-Net Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u ...
- POJ 1258 Agri-Net|| POJ 2485 Highways MST
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...
- MST系列
1.POJ2485 Highways 蛮水的 数组一开始开小了卡了一会儿 我可能是个傻逼 #include<iostream> #include<cstdio> #includ ...
- poj图论解题报告索引
最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...
- H:Highways
总时间限制: 1000ms 内存限制: 65536kB描述The island nation of Flatopia is perfectly flat. Unfortunately, Flatopi ...
随机推荐
- Moqui学习之 Step by Step OrderProcureToPayBasicFlow
/** Get a service caller to call a service synchronously. */ //ServiceCallSync sync(); /** Map of na ...
- linux 查看服务器性能常用命令
一.top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器 下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来 ...
- zoj3890 BFS
就是搜. #include<stdio.h> #include<string.h> #include<queue> using namespace std; #de ...
- ActiveMQ 入门使用实例
1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/download-archives.html 2.运行ActiveMQ 解压缩apache-active ...
- Java基础-四要素之一《封装》
封装从字面上来理解就是包装的意思,专业点就是信息隐藏,是指利用抽象数据类型将数据和基于数据的操作封装在一起,使其构成一个不可分割的独立实体,数据被保护在抽象数据类型的内部,尽可能地隐藏内部的细节,只保 ...
- Java怎么实现多继承的功效
Java不支持多继承,但是通过一些巧妙的设计来达到和多继承同样的效果 通过接口.内隐类,继承.实现,互相配合,达到多继承的效果 1.Java中一个类不能继承多个具体class. 2.一个类只可继 ...
- 【BZOJ-3651&3081】网络通信&StrangeRegulations Link-Cut-Tree
3651: 网络通信 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 90 Solved: 61[Submit][Status][Discuss] D ...
- BZOJ4590 自动刷题机
Description 曾经发明了信号增幅仪的发明家SHTSC又公开了他的新发明:自动刷题机--一种可以自动AC题目的神秘装置.自动 刷题机刷题的方式非常简单:首先会瞬间得出题目的正确做法,然后开始写 ...
- BZOJ1083 繁忙的都市
Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...
- UVA 1149 Bin Packing
传送门 A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the sa ...