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/ ...
随机推荐
- Five ways to maximize Java NIO and NIO.2--reference
Java NIO -- the New Input/Output API package-- was introduced with J2SE 1.4 in 2002. Java NIO's purp ...
- 上传文件时 ContentType 浏览器差异
上传图片时,ie会把 jpg.jpeg翻译成image/pjpeg,png翻译成image/x-png . 火狐.chrome则很标准:jpg.jpeg翻译成image/jpeg,png翻译成imag ...
- ArcEngine:栅格分级渲染
ArcEngine对矢量数据进行风格化实在是得心应手,同样的对于栅格图像也能进行风格化!以前没接触过,今天正好需要,做出了栅格图像的渲染!下面实现的思路: 1.定义渲染的一系列接口 2.判断图像是否建 ...
- javascript操作json方法
/*新增json的对象属性*/ var json = {}; json["subjectName"] = "ddd"; json.teacherlist = & ...
- 9.30 noip模拟试题
时限均为1s,内存 256MB 1.某种密码(password.*) 关于某种密码有如下描述:某种密码的原文A是由N个数字组成,而密文B是一个长度为N的01数串,原文和密文的关联在于一个钥匙码KEY. ...
- PHP操作Oracle数据库
原文出处 (这是来自“百度文库”中的文章写得很不错) PHP操作Oracle数据库(OCI数据抽象层)OCI(Oracle 8 Call-Interface)是PHP中内置的数据库抽象层函数.下面针对 ...
- CSS Hack (各个浏览器兼容的问题)
写css样式的时候,恐怕最头疼的就是各个浏览器下的兼容性问题,即css hack,明明感觉应该是对的,但是就是出不来效果,我根据平时所接触的,总结一下关于兼容 性的技巧,希望可以对大家有所帮助…… C ...
- WPF Paragraph获取或修改文本内容
一.说明 Paragraph继承自Block,Block继承自TextElement,在TextElement中 // // 摘要: // 获取表示元素中内容末尾的 System.Windows.Do ...
- Android中的Adapter 详解
http://blog.csdn.net/tianfeng701/article/details/7557819 (一) Adapter介绍 Android是完全遵循MVC模式设计的框架,Activi ...
- cookie防篡改
概述: 除了 session 外,一般不会在客户端的 cookies 里保存过于重要的凭据,但电商应用有时候不可避免地存储了一些敏感数据到客户端,当然不希望被篡改. 目的: 让服务器端能识别cooki ...