find the most comfortable road

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5359    Accepted Submission(s): 2327

Problem Description
XX
星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam
Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对
Flycar的“舒适度”有特殊要求,即乘坐过程中最高速度与最低速度的差越小乘坐越舒服
,(理解为SARS的限速要求,flycar必须瞬间提速/降速,痛苦呀 ),
但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。
 
Input
输入包括多个测试实例,每个实例包括:
第一行有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, 表示寻路的起终点。
 
Output
每个寻路要求打印一行,仅输出一个非负整数表示最佳路线的舒适度最高速与最低速的差。如果起点和终点不能到达,那么输出-1。
 
Sample Input
4 4
1 2 2
2 3 4
1 4 1
3 4 2
2
1 3
1 2
 
Sample Output
1
0
题解:错了好多次啊。。。
代码:
 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int INF=0x7f7f7f7f;
const int MAXN=;
const int MAXM=;
int pre[MAXN];
struct Node{
int u,v,d;
};
Node dt[MAXM];
int cmp(Node a,Node b){
return a.d<b.d;
}
int find(int x){
int r=x;
while(r!=pre[r])r=pre[r];
// pre[x]=r;
return r;
}
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<m;i++){
scanf("%d%d%d",&dt[i].u,&dt[i].v,&dt[i].d);
}
sort(dt,dt+m,cmp);
int Q,s,e,f1,f2;
scanf("%d",&Q);
while(Q--){
int ans=INF;//这个竟然被我写到外边
scanf("%d%d",&s,&e);
for(int j=;j<m;j++){
for(int i=;i<=n;i++)pre[i]=i;
for(int i=j;i<m;i++){
int u=dt[i].u,v=dt[i].v,d=dt[i].d;
f1=find(u);f2=find(v);
if(f1!=f2)pre[f2]=f1;
if(find(s)==find(e)){
ans=min(ans,d-dt[j].d);
break;
}
}
}
if(ans==INF)puts("-1");
else printf("%d\n",ans);
}
}
return ;
}
 

find the most comfortable road(并差集,找差值最小的权值)的更多相关文章

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

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

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

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

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

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

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

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

  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 1589 Find The Most Comfortable Road 最小生成树+枚举

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

  7. HDU1598 find the most comfortable road 【并查集】+【枚举】

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

  8. find the most comfortable road(hdu1598)不错的并查集

    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 (并查集+枚举)

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

随机推荐

  1. 用1个 2个3个 5个div实现 十字架

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 操作native window的QxtWindowSystem (好像是一个IM的一部分)

    http://libqxt.bitbucket.org/doc/0.6/qxtwindowsystem.html https://github.com/psi-plus/plugins/blob/ma ...

  3. Python GUI开发环境的搭建

    原文:Python GUI开发环境的搭建 最近对Python的开发又来了兴趣,对于Python的开发一直停留在一个表面层的认识,玩的部分比较大. Python的入手简单,语法让人爱不释手,在网络通信方 ...

  4. CCNA实验(4) -- EIGRP

    enableconf tno ip do loenable pass ciscoline con 0logg syncexec-t 0 0line vty 0 4pass ciscologg sync ...

  5. 阻止长按复制页面中的内容;zepto中touch中的应用必须先加载event模块之后;

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 刷新指定行或区 cell

    //一个section刷新 NSIndexSet *indexSetA = [[NSIndexSet alloc]initWithIndex:3];    //刷新第3段 [tableview rel ...

  7. STL: generate ,geterate_n

    在随机生成一定范围不重复数时用到random_shuffle函数,之前填充数组都是用for循环, 想到之前python中的range生成序列,于是在C++中找到对应的generate用来生成所需数组. ...

  8. JavaBean组件在JSP文档中的应用

    Bean: package cn.donghaua.bean; public class StringBean { private String message = "No message ...

  9. BZOJ 2208: [Jsoi2010]连通数( DFS )

    n只有2000,直接DFS就可以过了... -------------------------------------------------------------------------- #in ...

  10. C++内联函数、函数模板之于头文件

    一.基本说明 C++标准中提到,一个编译单元是指一个.cpp文件以及它所include的所有.h文件,.h文件里的代码将会被扩展到包含它的.cpp文件里,然后编译器编译该.cpp文件为一个.obj文件 ...