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属于同一个集合,即可以连通时停止.过程类似于 ...
随机推荐
- 基于bootstarp的Dailog
oaoDailog开发帮助 1. 帮助文档关键字 boostrap模态框oaoDailog 2. 使用场景 当网页上点击某个按钮需要给予用户提示确认,用户点击确认按钮才 ...
- 轻量数据库SQLiteDataBase的相关操作方法
一.查询操作: 查询操作比较复杂,主要有如下操作: db.rawQuery(String sql, String[] selectionArgs); db.query(String table, St ...
- Scala——面向对象和函数式编程语言
Scala Scala是一门运行时基于JVM的编程语言,具备函数式编程和面向对象特点. 基本知识 basics 任意词均可作为符号名,对于关键词,以反引号包裹,避免使用下划线,避免带美元符的名字. 声 ...
- py2exe打包遇到的问题
py2exe打包python成.exe文件 打包过程和结果 1.创建setup脚本打包文件,其中设置打包的属性和方法.注意:尽量将被打包文件和此打包脚本放在同目录下(因为在尝试非同目录下时,出现了非可 ...
- SQLite-编译指示
SQLite – 编译指示 SQLite编译指示命令(PRAGMA)是一个特殊的命令是用于控制各种环境变量和状态标志在SQLite的环境.编译指示值可以读取,也可以根据需求设置. 语法: 查询当前的编 ...
- css属性代码大全总结(一)
一 CSS文字属性: color : #999999; /*文字颜色*/ font-family : 宋体,sans-serif; /*文字字体*/ font-size : 9pt; /*文字大小*/ ...
- 相机标定:PNP基于单应面解决多点透视问题
利用二维视野内的图像,求出三维图像在场景中的位姿,这是一个三维透视投影的反向求解问题.常用方法是PNP方法,需要已知三维点集的原始模型. 本文做了大量修改,如有不适,请移步原文: ...
- 闲着无聊时写的一个调用天气 API 的小 Demo
分为两个部分--调用以及实现,并且由于不想折腾,直接使用了 Console 来调用. 通过firefox直接调用 Main 入口,调用以及输出 调用部分没什么好说的,主要是针对 dynamic 类型的 ...
- [Intermediate Algorithm] - Everything Be True
题目 所有的东西都是真的! 完善编辑器中的every函数,如果集合(collection)中的所有对象都存在对应的属性(pre),并且属性(pre)对应的值为真.函数返回ture.反之,返回false ...
- change project compliance and jre to 1.5
这个主要检查一下几点 项目的jdk为1.7 java版本设置为1.7 java compiler 的页面设置为以下,并且去掉勾选java compiler 下面的 enableproject spec ...