【题意】

  有n个绿洲, m条道路,每条路上有一个温度,和一个路程长度,从绿洲s到绿洲t,求一条道路的最高温度尽量小, 如果有多条, 选一条总路程最短的。

Input
Input consists of several test cases. Your program must process all of them.
The first line contains two integers N and E (1 ≤ N ≤ 100; 1 ≤ E ≤ 10000) where N represents the
number of oasis and E represents the number of paths between them. Next line contains two distinct
integers S and T (1 ≤ S, T ≤ N) representing the starting point and the destination respectively. The
following E lines are the information the group gathered. Each line contains 2 integers X, Y and 2 real
numbers R and D (1 ≤ X, Y ≤ N; 20 ≤ R ≤ 50; 0 < D ≤ 40). It means there is a path between X and
Y , with length D km and highest temperature RoC. Each real number has exactly one digit after the
decimal point. There might be more than one path between a pair of oases.
Output
Print two lines for each test case. The first line should give the route you find, and the second should
contain its length and maximum temperature.
Sample Input
6 9
1 6
1 2 37.1 10.2
2 3 40.5 20.7
3 4 42.8 19.0
3 1 38.3 15.8
4 5 39.7 11.1
6 3 36.0 22.5
5 6 43.9 10.2
2 6 44.2 15.2
4 6 34.2 17.4
Sample Output
1 3 6
38.3 38.3

【分析】

  我们可以先求出最大温度的最小值,然后把小于等于这个温度的边加进图中跑最短路。

  最短路就不说了,现在就是要求最小瓶颈路。

  最小瓶颈路有两个方法,

  1、二分+BFS

    二分之后沿着小于等于这个温度的边走,只需判断能否走到终点,所以是mlogn的。

  2、

    但其实可以nlogn把图上所有两点的最小瓶颈路求出来,就是求出最小瓶颈树,那么两点之间的唯一路径就是他们的最小瓶颈路。

    而最小生成树就是一个最小瓶颈树。

  [其实这个,我也不是很会证明的说- -谁能告诉我- -]

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define Maxn 110
#define Maxm 10010
#define INF 0xfffffff int n,m,st,ed; struct node
{
int x,y,c,d;
int next;
}tt[Maxm],t[Maxm*];
int len,first[Maxn]; bool cmp(node x,node y) {return x.c<y.c;}
// double mymax(double x,double y) {return x>y?x:y;}
int mymax(int x,int y) {return x>y?x:y;} int fa[Maxn];
int ffa(int x)
{
if(fa[x]!=x) fa[x]=ffa(fa[x]);
return fa[x];
} void ins(int x,int y,int c)
{
t[++len].x=x;t[len].y=y;t[len].c=c;
t[len].next=first[x];first[x]=len;
} int mx[Maxn];
void dfs(int x,int f)
{
for(int i=first[x];i;i=t[i].next) if(t[i].y!=f)
{
int y=t[i].y;
mx[y]=mymax(mx[x],t[i].c);
dfs(y,x);
}
} queue<int > q;
int pre[Maxn],dis[Maxn];
bool inq[Maxn];
void spfa()
{
while(!q.empty()) q.pop();
// for(int i=1;i<=n;i++) dis[i]=INF;
memset(dis,,sizeof(dis));
memset(inq,,sizeof(inq));
q.push(ed);inq[ed]=;dis[ed]=;
while(!q.empty())
{
int x=q.front();
for(int i=first[x];i;i=t[i].next)
{
int y=t[i].y;
if(dis[y]>dis[x]+t[i].c)
{
dis[y]=dis[x]+t[i].c;
pre[y]=x;
if(!inq[y])
{
q.push(y);
inq[y]=;
}
}
}
inq[x]=;q.pop();
}
if(dis[st]>=INF-) return;
int now=st;
while(now!=ed)
{
printf("%d ",now);
now=pre[now];
}
printf("%d\n",ed);
printf("%.1lf %.1lf\n",dis[st]*1.0/,mx[st]*1.0/);
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
scanf("%d%d",&st,&ed);
for(int i=;i<=m;i++)
{
double c,d;
scanf("%d%d%lf%lf",&tt[i].x,&tt[i].y,&c,&d);
tt[i].c=(int)round(c*);tt[i].d=(int)round(d*);
}
sort(tt+,tt++m,cmp);
for(int i=;i<=n;i++) fa[i]=i;
int cnt=;
memset(first,,sizeof(first));
len=;
for(int i=;i<=m;i++)
{
if(ffa(tt[i].x)!=ffa(tt[i].y))
{
fa[ffa(tt[i].x)]=ffa(tt[i].y);
cnt++;
ins(tt[i].x,tt[i].y,tt[i].c);
ins(tt[i].y,tt[i].x,tt[i].c);
}
if(cnt==n-) break;
}
mx[ed]=;
dfs(ed,);
len=;
memset(first,,sizeof(first));
for(int i=;i<=m;i++) if(tt[i].c<=mx[st])
{
ins(tt[i].x,tt[i].y,tt[i].d);
ins(tt[i].y,tt[i].x,tt[i].d);
}
spfa();
}
return ;
}

2016-11-01 15:57:34

【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)的更多相关文章

  1. uva 10816 Travel in Desert(简单的好题~两种方法)

    题意: 给出 一个图 点与点之间的路径上有两个权值 路径长度和温度 要求在所走路径中的温度的最大值最小的前提下 走最短路径 解题思路1: 首先用 最小生成树 的方法走出 最小瓶颈路 .把在这期间用到的 ...

  2. 【洛谷P2504】聪明的猴子 最小瓶颈树

    题目大意:给定一张 N 个顶点的完全图,边有边权,求该完全图的一棵最小瓶颈树. 最小瓶颈树:一棵最大边权值在同一张图的所有生成树中最小,即:最大边权值最小的生成树,其值为该树的最大边权的权值. 引理1 ...

  3. 【UVA10816】Travel in Desert (最小瓶颈路+最短路)

    UVA10816 Travel in Desert 题目大意 沙漠中有一些道路,每个道路有一个温度和距离,要求s,t两点间的一条路径,满足温度最大值最小,并且长度最短 输入格式 输入包含多组数据. 每 ...

  4. 【UVA 11354】 Bond (最小瓶颈生成树、树上倍增)

    [题意] n个点m条边的图 q次询问 找到一条从s到t的一条边 使所有边的最大危险系数最小 InputThere will be at most 5 cases in the input file.T ...

  5. POJ 2253 Frogger【最短路变形/最小生成树的最大权/最小瓶颈树/A到B多条路径中的最小的最长边】

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  6. POJ 2395 Out of Hay 草荒 (MST,Kruscal,最小瓶颈树)

    题意:Bessie要从牧场1到达各大牧场去,他从不关心他要走多远,他只关心他的水袋够不够水,他可以在任意牧场补给水,问他走完各大牧场,最多的一次需要多少带多少单位的水? 思路:其实就是要让所带的水尽量 ...

  7. UVa 11354 邦德(最小瓶颈路+LCA)

    https://vjudge.net/problem/UVA-11354 题意: 有n个城市m条道路,每条道路有一个危险系数.先在有若干个询问,要求找到一条从s到t的路,使得途径所有边的最大危险系数最 ...

  8. POJ 1797 Heavy Transportation 【最大生成树的最小边/最小瓶颈树】

    Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...

  9. 【uva 534】Frogger(图论--最小瓶颈路 模版题)

    题意:平面上有N个石头,给出坐标.一只青蛙从1号石头跳到2号石头,使路径上的最长便最短.输出这个值.(2≤N≤200) 解法:最小瓶颈树.而由于这题N比较小便可以用2种方法:1.最短路径中提到过的Fl ...

随机推荐

  1. Smokeping 监控部署及配置

    安装参见: https://github.com/oetiker/SmokePing/blob/master/doc/smokeping_install.pod 1 Smokeping *** Gen ...

  2. (转)我所理解的OOP——UML六种关系

    原文地址:http://www.cnblogs.com/dolphinX/p/3296681.html 最近由于经常给公司的小伙伴儿们讲一些OOP的基本东西,每次草纸都被我弄的很尴尬,画来画去自己都乱 ...

  3. mysql中 的 ENGINE = innodb; 是什么意思?

    存储引擎是innodb.nnoDB 是 MySQL 上第一个提供外键约束的数据存储引擎,除了提供事务处理外,InnoDB 还支持行锁,提供和 Oracle 一样的一致性的不加锁读取,能增加并发读的用户 ...

  4. Java Mybatis 传参方式

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

  5. C#微信公众号开发 -- (一)开发之前的准备

    本系列文章讲述的是利用C#语言开发微信公众号的实例教程,主要是服务号的开发(因为订阅号不能获取微信开发的高级接口) 想要开发微信服务公众号,首先必须要有一个认证的微信服务号,这样才能够使用微信提供的所 ...

  6. Object-C在Nil上调用方法

    在Object-C中,nil对象的作用等同于很多其它语言的NULL指针.不同的地方在于,在nil上调用方法不会导致程序崩溃或抛出异常. 这种技术被用在很多地方,但是对于我们来讲,最主要的就是我们不用在 ...

  7. google模拟各种Android手机浏览器方法

    在开始--运行 输入 chrome.exe --user-agent="Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/ ...

  8. 10.20_wiki

    XWiki:官网.Documentation.User's GuideProgrammer's GuideAdministrator's Guide Developer's Guide (1) htt ...

  9. 04_过滤器Filter_03_多个Filter的执行顺序

    [Filter链] *在一个web应用中,可以开发编写多个Filter,这些Filter组合起来称为一个Filter链. *web服务器根据Filter在web.xml中的注册顺序,决定先调用哪个Fi ...

  10. 九度OJ 1468 Sharing -- 哈希

    题目地址:http://ac.jobdu.com/problem.php?pid=1468 题目描述: To store English words, one method is to use lin ...