题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1598

题目大意:

XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Flycar的“舒适度”有特殊要求,即乘坐过程中最高速度与最低速度的差越小乘坐越舒服 ,(理解为SARS的限速要求,flycar必须瞬间提速/降速,痛苦呀 ),
但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。

解题思路:

对边进行排序,从小到大枚举下界,依次加入每条边,知道恰好目标点连通,那么正好是最大值-最小值。答案取最小值

 #include<bits/stdc++.h>
using namespace std;
const int maxn = + ;
const int INF = 0x3f3f3f3f;
struct node
{
int u, v, w;
bool operator <(const node & a)const
{
return w < a.w;
}
}a[maxn];
int p[maxn];
void init()
{
for(int i = ; i < maxn; i++)p[i] = i;
}
int Find(int x)
{
return x == p[x] ? x : p[x] = Find(p[x]);
}
void Union(int x, int y)
{
p[Find(x)] = Find(y);
}
int main()
{
int n, m;
while(cin >> n >> m)
{
for(int i = ; i < m; i++)
{
cin >> a[i].u >> a[i].v >> a[i].w;
}
sort(a, a + m);
int t, u, v;
cin >> t;
while(t--)
{
cin >> u >> v;
int ans = INF;
for(int start = ; start < m; start++)
{
init();
for(int end = start; end < m; end++)
{
Union(a[end].u, a[end].v);
if(Find(u) == Find(v))
{
ans = min(ans, a[end].w - a[start].w);
}
}
}
if(ans < INF)cout<<ans<<endl;
else cout<<"-1"<<endl;
}
}
return ;
}

hdu-1598 find the most comfortable road---kruskal+枚举下界的更多相关文章

  1. HDU 1598 find the most comfortable road 并查集+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000 ...

  2. hdu 1598 find the most comfortable road (并查集+枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/ ...

  3. HDU 1598 find the most comfortable road(最小生成树之Kruskal)

    题目链接: 传送门 find the most comfortable road Time Limit: 1000MS     Memory Limit: 32768 K Description XX ...

  4. hdu 1598 find the most comfortable road(枚举+卡鲁斯卡尔最小生成树)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  5. hdu 1598 find the most comfortable road (并查集)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. HDU 1598 find the most comfortable road (MST)

    find the most comfortable road Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 1598 find the most comfortable road(并查集+枚举)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. HDU 1589 Find The Most Comfortable Road 最小生成树+枚举

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. HDU 1598 find the most comfortable road (罗列+Kruskal) 并检查集合

    Problem Description XX星有很多城市,城市之间通过一种奇怪的快速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流.每条SARS都对行驶 ...

  10. HDU - 1598 find the most comfortable road 【最小生成树】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1598 思路 用kruskal 算法 将边排序后 跑 kruskal 然后依次将最小边删除 再去跑 kr ...

随机推荐

  1. Filter的使用及其生命周期介绍

    一.Filter 1. Filter简介 > Filter翻译为中文是过滤器的意思. > Filter是JavaWeb的三大web组件之一:Servlet.Filter.Listener ...

  2. LCD浮点数显示函数的探讨

    LCD浮点数显示函数的探讨 原创 2017年12月19日 单片机开放附赠的学习资料里面很少见到显示浮点数的函数,显示浮点数的操作也相当烦坠! 一般转换显示法 拿STM32单片机资源,我们选取ADC采样 ...

  3. Windows 命令行方式打印和设置变量

    echo %PATH% http://blog.csdn.net/snlei/article/details/7211770

  4. 虚拟机上安装Cell节点(12.1.2.3.3)

    安装介质下载 打开firefox,输入:https://edelivery.oracle.com 点击"Sign In",输入帐号.密码,登陆edelivery网站.       ...

  5. 《SQL 进阶教程》 自连接排序

    子查询所做的,是计算出价格比自己高的记录的条数并将其作为自己的位次 -- 自连接实现排序功能SELECT P1.name,P1.price,(SELECT COUNT(P2.price)FROM Pr ...

  6. python实现王者荣耀英图片收集

    一个python写的小爬虫项目,爬虫相关的很容易写,关键是怎么找到爬取图片的位置. 图片位置分析 hero_list_url = 'http://pvp.qq.com/web201605/js/her ...

  7. Proxy opening connection toSpringClound配置豪猪hystrixDashboard发生

    Proxy opening connection to: http://localhost:8001/hystrix.stream 配置hystrixDashboard发生的错误.一直在寻找 最后发现 ...

  8. ACM 大神的经验加技巧(当然不是我的拉——

    大神 犯错合集及需要注意的东西 1.在一个地图求最大面积的类问题中,要注意障碍结点的影响. 2.ll(),表示的是在运算后把括号内强制转化为类型ll,而(ll)表示后面的每个玩意都强制转化为类型ll. ...

  9. linux高级编程基础系列:线程间通信

    linux高级编程基础系列:线程间通信 转载:原文地址http://blog.163.com/jimking_2010/blog/static/1716015352013102510748824/ 线 ...

  10. (转)CentOS 6下配置软RAID图文详解

    CentOS 6下配置软RAID图文详解 原文:http://blog.51cto.com/hujiangtao/1929620 一.RAID 简介 RAID 是英文Redundant Array o ...