find the most comfortable road
但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。
第一行有2个正整数n (1<n<=200)和m (m<=1000),表示有N个城市和M条SARS。
接下来的行是三个正整数StartCity,EndCity,speed,表示从表面上看StartCity到EndCity,限速为speedSARS。speed<=1000000
然后是一个正整数Q(Q<11),表示寻路的个数。
接下来Q行每行有2个正整数Start,End, 表示寻路的起终点。
0
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f; int n,m,set[];
struct Edge
{
int u,v;
int w;
} edge[];
int cmp(const struct Edge a, const struct Edge b)
{
return a.w < b.w;
}
void init()
{
for(int i = ; i <= n; i++)
set[i] = i;
}
int find(int x)
{
if(set[x] != x)
set[x] = find(set[x]);
return set[x];
}
void merge(int x, int y)
{
int xx = find(x);
int yy = find(y);
if(xx != yy)
set[xx] = yy;
}
int main()
{
int i,j; while(~scanf("%d %d",&n,&m))
{
for(i = ; i < m; i++)
scanf("%d %d %d",&edge[i].u,&edge[i].v,&edge[i].w);
sort(edge,edge+m,cmp); int test;
scanf("%d",&test);
while(test--)
{
int s,t;
scanf("%d %d",&s,&t);
int ans = INF;
for(i = ; i < m; i++)
{
init();
for(j = i; j < m; j++)
{
merge(edge[j].u,edge[j].v);
if(find(s) == find(t))
break;
}
if(j >= m)
break;
if(ans > edge[j].w-edge[i].w)
ans = edge[j].w-edge[i].w;
}
if(ans < INF)
printf("%d\n",ans);
else printf("-1\n");
}
}
return ;
}
find the most comfortable road的更多相关文章
- HDU 1598 find the most comfortable road(最小生成树之Kruskal)
题目链接: 传送门 find the most comfortable road Time Limit: 1000MS Memory Limit: 32768 K Description XX ...
- hdu 1598 find the most comfortable road(枚举+卡鲁斯卡尔最小生成树)
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 1598 find the most comfortable road 并查集+贪心
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000 ...
- HDU 1598 find the most comfortable road (MST)
find the most comfortable road Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- HDU-1598 find the most comfortable road
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- find the most comfortable road(并差集,找差值最小的权值)
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 1589 Find The Most Comfortable Road 最小生成树+枚举
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU1598 find the most comfortable road 【并查集】+【枚举】
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- find the most comfortable road(hdu1598)不错的并查集
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu 1598 find the most comfortable road (并查集+枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/ ...
随机推荐
- Android制作粒子爆炸特效
简介 最近在闲逛的时候,发现了一款粒子爆炸特效的控件,觉得比较有意思,效果也不错. 但是代码不好扩展,也就是说如果要提供不同的爆炸效果,需要修改的地方比较多.于是我对源代码进行了一些重构,将爆炸流程和 ...
- JavaScript 数据类型转换(显式与隐式)
一.数据类型 JS中有5中简单数据类型(也称为基本数据类型):Undefined.Null.Boolean.Number.String.还有一种复杂数据类型------Object,Object本质是 ...
- 关于HTTP请求报文和响应报文学习笔记
超文本传输协议(Hypertext Transfer Protocol,简称HTTP)是应用层的一种通信协议.它是一种请求/响应式的协议,即一个客户端与服务器建立连接后,向服务器发送一个请求;服务器接 ...
- TFS 安装与管理
整了几天TFS,把相关的一些配置与安装的要点简单记下,希望对大家有用.本篇主要是安装与配置上的内容,下一篇会介绍如何使用以及使用方面的相关心得体会. 本篇内容简要: 1. 安装部署 1.1. 流 ...
- 如何使用node中的buffer
介绍:Buffer类是一个全局类,是一个比较罕见不需要require( ‘buffer’ )就可以使用的类,Buffer类似与数组也有length, 它里面的元素为16进制的两位数,即 0-255的数 ...
- Android中dip,dp,sp,pt和px的区别
dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不依赖像素. ...
- oracle中获取特定时间的前一天
select to_char(to_date('@rq','YYYY-MM-DD')-1,'YYYY-MM-DD') FROM DUAL 把@rq换成你要的时间就行了
- 【转】 iOS-Core-Animation-Advanced-Techniques(七)
高效绘图.图像IO以及图层性能 高效绘图 原文:http://www.cocoachina.com/ios/20150106/10840.html 不必要的效率考虑往往是性能问题的万恶之源. ——Wi ...
- Objective-C的对象模型 http://foredoomed.org/blog/2014/02/24/object-modeling-of-objective-c/
Objective-C是一门面向对象,并且在C的基础上加入了Smalltalk式的消息机制而形成的编程语言,它主要被苹果公司用于开发Mac OS X和iOS操作系统.既然Objective-C是面向对 ...
- jQuery 效果- 动画
jQuery animate() 方法允许您创建自定义的动画. jQuery 动画实例 jQuery jQuery 动画 - animate() 方法 jQuery animate() 方法用于创建自 ...