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/ ...
随机推荐
- java中关于public class
在编写类的时候可以使用两种方式定义类: public class定义类: class定义类: 1,如果一个类声明的时候使用了public class进行了声明,则类名称必须与文件名称完 ...
- 10.7 noip模拟试题
楼[问题背景]zhx 为他的妹子造了一幢摩天楼.[问题描述]zhx 有一幢摩天楼. 摩天楼上面有 M 个观光电梯,每个观光电梯被两个整数
- Android开发手记(32) 使用摄像头拍照
在Android中,使用摄像头拍照一般有两种方法, 一种是调用系统自带的Camera,另一种是自己写一个摄像的界面. 我们要添加如下权限: <uses-permission android:na ...
- ASP.NET Web API 文件產生器 - 使用 Swagger
转帖:http://kevintsengtw.blogspot.hk/2015/12/aspnet-web-api-swagger.html Swagger 是一套 API 互動文件產生器,使用 HT ...
- SQL Server死锁日志各字段含义
使用跟踪标记 1204 --打开跟踪标记 DBCC TRACEON (1204,-1) --关闭跟踪标记 DBCC TRACEOFF (1204,-1) 处于死锁状态时,跟踪标记 1204 在等待的线 ...
- 使用XLinq.XElement读取带Namespace(命名空间)的XML
简介 本文主要介绍通过XELemet去读取含有namespaces(xmlns)的XML,这也是偶然间发现这个问题的,一个群里的小伙伴突然问起这个,以此记录一下. 背景 一个XML文档可能包括来自多个 ...
- 关于ASIHTTPRequest连续请求,并发连续,间隔时间很小崩溃问题
在不停的刷新ASIHttpRequest的网络请求时,总是在刷新几次之后,整个app崩溃掉.我的app使用的ARC模式,以为可以自动释放到request的请求.经过摸索,还是需要在dealloc函数加 ...
- js实现滑动解锁功能(PC+Moblie)
http://dummyimage.com/600x400/ http://placehold.it/140x70 实现效果: css样式代码略. html代码: 页面上导入了jquery.mobil ...
- 3 - testng.xml
TestNG的调用有以下几种方式: testng.xml ant 命令行 这部分主要介绍testng.xml的格式. 当前testng.xml的DTD(文档类型定义(Document Type Def ...
- web版扫雷小游戏(一)
作为一名程序猿,平时的爱好也不多,说起游戏,我不太喜欢大型的网游,因为太耗时间,偶尔玩玩经典的单机小游戏,比如windows下自带的游戏扫雷(秀一下,高级下最高纪录110s). 现阶段正在致力于web ...