POJ2485 Highways 【MST】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 22842 | Accepted: 10525 |
Description
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 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
求MST中的最大边
#include <stdio.h>
#include <string.h> #define maxn 505
#define inf 0x3f3f3f3f int G[maxn][maxn], n;
int dis[maxn];
bool vis[maxn]; void getMap() {
scanf("%d", &n);
int i, j;
for(i = 0; i < n; ++i)
for(j = 0; j < n; ++j)
scanf("%d", &G[i][j]);
} int getNext() {
int i, pos = -1, val = inf;
for(i = 0; i < n; ++i)
if(!vis[i] && dis[i] < val) {
val = dis[i]; pos = i;
}
return pos;
} void solve() {
int i, u, ans = 0;
for(i = 0; i < n; ++i) {
vis[i] = 0; dis[i] = inf;
}
dis[u=0] = 0;
while(u != -1) {
vis[u] = 1;
if(ans < dis[u]) ans = dis[u];
for(i = 0; i < n; ++i)
if(!vis[i] && dis[i] > G[u][i])
dis[i] = G[u][i];
u = getNext();
}
printf("%d\n", ans);
} int main() {
int t;
scanf("%d", &t);
while(t--) {
getMap();
solve();
}
return 0;
}
POJ2485 Highways 【MST】的更多相关文章
- 【MST】P2323 [HNOI2006]公路修建问题
Description 给定 \(n\) 个点 \(m - 1\) 条无向边,每条边有两种边权,贵一点的和便宜一点的.要求至少选择 \(k\) 条贵边使得图联通且花费最大的边权值最小. Input 第 ...
- Bzoj1083 1083: [SCOI2005]繁忙的都市【MST】
大水题,真不知道出题者是怎么把这么水的题出的这么长的TAT 其实这题在于考语文水平,一共三个要求,前两个要求意思就是要选出的道路是树形的,最后一个要求就是要权值最小,于是整个题意说白了就是求一棵MST ...
- Codeforces 1095F Make It Connected 【MST】
<题目链接> 题目大意: 给定一张n个顶点(每个顶点有点权)的无向图,并且给出边权为wi的m条边,顶点u和顶点v直接如果建边,边权为a_u + a_v,求图连通的最小边权和. 解题分析: ...
- POJ1751 Highways【最小生成树】
题意: 给你N个城市的坐标,城市之间存在公路,但是由于其中一些道路损坏了,需要维修,维修的费用与公路长成正比(公路是直的). 但现有M条公路是完整的,不需要维修,下面有M行,表示不需要维修的道路两端的 ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
- 【AtCoder3611】Tree MST(点分治,最小生成树)
[AtCoder3611]Tree MST(点分治,最小生成树) 题面 AtCoder 洛谷 给定一棵\(n\)个节点的树,现有有一张完全图,两点\(x,y\)之间的边长为\(w[x]+w[y]+di ...
- 【AtCoder2134】ZigZag MST(最小生成树)
[AtCoder2134]ZigZag MST(最小生成树) 题面 洛谷 AtCoder 题解 这题就很鬼畜.. 既然每次连边,连出来的边的权值是递增的,所以拿个线段树xjb维护一下就可以做了.那么意 ...
- 【LCA+MST】BZOJ3732-Network
[题目大意] 给你N个点的无向图 (1 <= N <= 15,000),记为:1…N.图中有M条边 (1<=M<=30,000) ,第j条边的长度:d_j (1<=d_j ...
- 【CF125E】MST Company(凸优化,最小生成树)
[CF125E]MST Company(凸优化,最小生成树) 题面 洛谷 CF 题解 第一眼看见就给人丽洁姐那道\(tree\)一样的感觉. 那么二分一个权值,加给所有有一个端点是\(1\)的边, 然 ...
随机推荐
- WordPress开启伪静态
一.NGINX 的话在 domain.conf 的 server 增加代码: location / { try_files $uri $uri/ /index.php?$args; } 如果使用的是 ...
- Python链表
class Node: ''' 节点类 链表节点结构 data next data: 节点保存的数据 _next: 保存下一个节点对象 ''' def __init__(self, data, pne ...
- 搭建ss总结
今天晚上做的事情: 1. https://www.vultr.com/ 购买vps 2. ssh连接到服务器 参照网上帖子安装 https://blog.csdn.net/littlepig19930 ...
- luogu P1586 四方定理(背包)
题意 题解 首先吐槽一下体面的第一句话.反正我不知道(可能是因为我太菜了) 可能没有睡醒,没看出来是个背包. 但告诉是个背包了应该就好做了. #include<iostream> #inc ...
- BZOJ 3325 [SCOI2013]密码 (逆模拟Manacher+构造)
题目大意:给你一个字符串每个位置和相邻两个位置为回文中心的最长回文串长度,让你构造一个合法的字典序最小的字符串 挺有意思的构造题 首先按照$Manacher$的思想还原$p$数组 定义$f_{ij}$ ...
- 特斯拉正加快部署第三代Autopilot自动驾驶计算机
新浪科技讯,北京时间 4 月 10 日下午消息,据电动汽车新闻网站 Electrek 报道,特斯拉正在加快部署第三代 Autopilot 自动驾驶计算机,因为当前一代产品的计算能力即将被耗尽. 201 ...
- Tomcat跨域资源共享
1.下载Jar包 cors-filter-1.7.jar java-property-utils-1.9.jar 下载完成后将Jar拷贝到tomcat下lib目录中 2.修改web.xml配置 在29 ...
- Qt之手动布局
简述 手动布局,可以实现和水平布局.垂直布局.网格布局等相同的效果,也可实现属于自己的自定义布局,当窗体缩放时,控件可以随之变化. 其对于坐标系的建立有严格要求,纯代码思维,使用复杂,不易维护,所以一 ...
- Oracle 切割字符查询
Oracle 切割字符查询 select * from view_psbaseinfo where DECODE('410782001125,411100000043', '', NULL, '410 ...
- spfile
1 让ORACLE自己主动从spfile启动 SQL> create spfile='/dev/vx/rdsk/vgora/lv_spfile' from pfile; SQL> sh ...