hdoj--1598--find the most comfortable road
find the most comfortable road
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5350 Accepted Submission(s): 2326
但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, 表示寻路的起终点。
4 4
1 2 2
2 3 4
1 4 1
3 4 2
2
1 3
1 2
1
0#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define INF 0xfffffff
int pre[10010],m,n;
struct node
{
int u,v;
int val;
}edge[10010];
int cmp(node s1,node s2)
{
return s1.val<s2.val;
}
void init()
{
for(int i=0;i<10010;i++)
pre[i]=i;
}
int find(int x)
{
if(pre[x]==x)
return x;
return pre[x]=find(pre[x]);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int minn;
for(int i=0;i<m;i++)
scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].val);
int p,s,e;
sort(edge,edge+m,cmp);
scanf("%d",&p);
while(p--)
{
scanf("%d%d",&s,&e);
minn=INF;
for(int i=0;i<m;i++)
{
init();
for(int j=i;j<m;j++)
{
int fx=find(edge[j].u);
int fy=find(edge[j].v);
if(fx!=fy)
pre[fx]=fy;
if(find(s)==find(e))
{
minn=min(minn,edge[j].val-edge[i].val);
break;
}
}
}
if(minn==INF)
printf("-1\n");
else
printf("%d\n",minn);
}
}
return 0;
}
hdoj--1598--find the most comfortable road的更多相关文章
- 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 (并查集+枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/ ...
- 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 (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 ...
- 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 思路 用kruskal 算法 将边排序后 跑 kruskal 然后依次将最小边删除 再去跑 kr ...
- HDU 1598 find the most comfortable road (罗列+Kruskal) 并检查集合
Problem Description XX星有很多城市,城市之间通过一种奇怪的快速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流.每条SARS都对行驶 ...
- HDU 1598 find the most comfortable road(枚举+并查集,类似于最小生成树)
一开始想到用BFS,写了之后,发现有点不太行.网上查了一下别人的解法. 首先将边从小到大排序,然后从最小边开始枚举,每次取比它大的边,直到start.end属于同一个集合,即可以连通时停止.过程类似于 ...
随机推荐
- 使用TortoiseSVN碰到的几个问题(2)-冲突解决, 图标重载
8)解决冲突 冲突分为两种:文件冲突---当两名(或更多)开发人员修改了同一个文件中相邻或相同的行时就会发生文件冲突.下面的属性冲突应该也属于文件冲突. 树冲突---当一名开发人员移动.重命名.删除一 ...
- HTML 5概述
HTML语言是一种简易的文件交换标准,用于物理的文件结构,它旨在定义文件内的对象和描述文件的逻辑结构,而并不定义文件的显示.由于HTML所描述的文件具有极高的适应性,所以特别适合于WWW的出版环境. ...
- 【PostgreSQL-9.6.3】extract函数
extract函数格式: extract (field from source) extract函数是从日期或者时间数值里面抽取子域,比如年.月.日等.source必须是timestamp.time. ...
- 【SQL】结构化查询语言
一:数据查询语言(DQL:Data Query Language): 其语句,也称为“数据检索语句”,用以从表中获得数据,确定数据怎样在应用程序给出.保留字SELECT是DQL(也是所有SQL)用得最 ...
- 【Oracle】恢复重做日志组
我们在Oracle的日常运维中,有可能会遇到重做日志组丢失的情况.下面我将模拟丢失不同状态的日志组,并分别给出解决办法: 重做日志有以下几种状态,如下: - CURRENT:此状态表示正在被 LGW ...
- 读书笔记之:C++ Primer (第4版)及习题(ch12-ch18) [++++]
读书笔记之:C++ Primer (第4版)及习题(ch12-ch18) [++++] 第12章 类 1. 类的声明与定义:前向声明,不完全类型 2. 从const函数返回*this 3. 可变数据成 ...
- jquery-pjax
项目介绍: Pjax是jQuery的一个插件,Pjax即pushState + Ajax,是实现无刷新Ajax加载并解决浏览器前进和后退问题的一个开源实现. 在2012年8月28日发布0.9版本. P ...
- javaee Properties键值对写入和读取方法
package Zjshuchu; import java.util.Properties; import java.util.Set; public class Demo03 { public st ...
- eoLinker上线两周年+ AMS V4.0 发布:全新UI界面,带来领先的API开发管理解决方案!
2018年7月,eoLinker 发布了<eoLinker AMS 2018年年中用户调研问卷>,前后经历一周的时间,共收集到超过1000份有效调查问卷.超过300个有效改进意见. eoL ...
- eas之去掉关闭eas页面时校验是否修改的提示
EditUI-------> public boolean checkBeforeWindowClosing() { boolean b = super.checkBefo ...