传送门

不算难吧

应该有思路的

还是太水了吧

(而且和货车运输很像的啊

----------------------------------------------------------------------------------------

题目大意

沙漠中有n 个绿洲(编号为1−n )和e 条连接绿洲的双向道路。每条道路都有一个长度d 和一个温度值r 。给定起点绿洲编号sss 和终点绿洲编号ttt ,求出一条sss 到ttt 的路径,使得这条路径上经过的所有道路的最高温度尽量小,如果有多条路径,选择总长度最短的那一条。

输入格式

输入包含多组数据。

每组数据第一行为两个整数n 和e 。表示绿洲数量和连接绿洲的道路数量。

每组数据第二行为两个整数s 和t 。表示起点和终点的绿洲编号。

接下来e 行,每行包含两个整数x,y 以及两个实数r,d,表明在绿洲x 和y 之间有一条双向道路相连,长度为d ,温度为r 。

输出格式

对于输入的每组数据,应输出两行,第一行表示你找到的路线,第二行包含两个实数,为你找出的路线的总长度与途经的最高温度。

----------------------------------------------------------------------------------------

如果只考虑最小的最大热度

那么本题就是一个最小瓶颈路问题

只需按照热度找一棵最小生成树即可。

但是,如果这样的路径有多个,

实际上是最小生成树有多个时,

要找到最短路径,

还得把热度不大于最小生成树中最大热度的边并且没在生成树中的边加到最小生成树中,

然后再找最短路。

#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define INF 0x3f3f3f3f
using namespace std; inline int read()
{
int sum = ,p = ;
char ch = getchar();
while(ch < '' || ch > '')
{
if(ch == '-')
p = -;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
(sum *= ) += ch - '';
ch = getchar();
}
return sum * p;
} const int maxm = ;
int n,m,s,t;
double tmp;
struct edge
{
int x,y;
double d,r;
} e[maxm];
int fa[];
struct edgee
{
int nxt,to;
double wei;
} ed[maxm * ];
int cnt,head[];
double dis[];
struct node
{
int u;
double d;
friend bool operator < (const node &a,const node &b)
{
return a.d > b.d;
}
};
priority_queue<node> q;
bool mrk[];
vector<int> path; bool cmp(edge a,edge b)
{
return a.r < b.r;
}
int findfa(int o)
{
if(o == fa[o]) return o;
else return fa[o] = findfa(fa[o]);
} void kruskal()
{
for(int i = ; i <= n; i++)
fa[i] = i;
sort(e+,e+m+,cmp);
for(int i = ; i <= m; i++)
{
int u = findfa(e[i].x);
int v = findfa(e[i].y);
if(u == v)
continue;
fa[u] = v;
tmp = max(tmp,e[i].r);
if(findfa(s) == findfa(t))
break;
}
} void add(int a,int b,double c)
{
ed[++cnt].nxt = head[a];
ed[cnt].to = b;
ed[cnt].wei = c;
head[a] = cnt;
} void dijkstra()
{
for(int i = ; i <= m; i++)
{
if(e[i].r > tmp)
break;
add(e[i].x,e[i].y,e[i].d);
add(e[i].y,e[i].x,e[i].d);
}
for(int i = ;i <= n;i++)
dis[i] = INF,fa[i] = ,mrk[i] = ;
dis[s] = ;
q.push((node){s,dis[s]});
while(q.size())
{
int u = q.top().u;
q.pop();
if(mrk[u])
continue;
mrk[u] = true;
for(int i = head[u]; i; i = ed[i].nxt)
{
int v = ed[i].to;
double z = ed[i].wei;
if(dis[v] > dis[u] + z)
{
dis[v] = dis[u] + z;
fa[v] = u;
q.push((node){v,dis[v]});
}
}
}
int x = t;
path.clear();
while(x != s)
{
path.push_back(x);
x = fa[x];
}
path.push_back(s);
for(int i = path.size()-;i >= ;i--)
printf("%d ",path[i]);
printf("%d\n",path[]);
} void pre()
{
cnt = ,tmp = ;
memset(e,,sizeof(e));
memset(ed,,sizeof(ed));
memset(mrk,,sizeof(mrk));
memset(head,,sizeof(head));
memset(fa,,sizeof(fa));
} int main()
{
while(~scanf("%d%d",&n,&m))
{
pre();
s = read(),t = read();
for(int i = ; i <= m; i++)
{
e[i].x = read(),e[i].y = read();
scanf("%lf%lf",&e[i].r,&e[i].d);
}
kruskal();
dijkstra();
printf("%.1lf %.1lf\n",dis[t],tmp);
}
return ;
}

注意:

题目稍稍有点坑

一定是先读入温度再读入长度

有几处double 打成 int

忽略了n 和 m

两个结构体的名搞混了

最最最坑:::对换行符和空格的输出特别严格qwq(这谁抗的住w

(sdqxt莫得未来

Travel in desert的更多相关文章

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

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

  2. 【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)

    [题意] 有n个绿洲, m条道路,每条路上有一个温度,和一个路程长度,从绿洲s到绿洲t,求一条道路的最高温度尽量小, 如果有多条, 选一条总路程最短的. InputInput consists of ...

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

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

  4. UVA-10816 Travel in Desert (最小瓶颈最短路)

    题目大意:给一张无向图,图中的每条边都有两个权值,长度d和热度r.找出从起点到终点的一条最大热度最小的路径,如果这样的路径有多条,选择一个最短的. 题目分析:如果只考虑最小的最大热度,那么本题就是一个 ...

  5. 图论 - Travel

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...

  6. 【BZOJ-1576】安全路径Travel Dijkstra + 并查集

    1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1044  Solved: 363[Sub ...

  7. Linux inode && Fast Directory Travel Method(undone)

    目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...

  8. HDU - Travel

    Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...

  9. 2015弱校联盟(1) - I. Travel

    I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...

随机推荐

  1. linux学习笔记1:linux驱动设备概述

  2. 动图演示23个鲜为人知的VSCode快捷键

    动图演示23个鲜为人知的VSCode快捷键 原文地址:dev.to/devmount/23… 代码同步浏览器 安装vccode 安装live server插件 尽管我在VS Code中经常使用许多快捷 ...

  3. IntelliJ IDEA构建多Module项目

    打开IDEA 创建完成项目后,我们创建子模块 可以看到common子模块创建成功,子模块的名字大家可以根据自己的实际需求来修改 下面我们再创建子模块 给子模块起个名字 现在已经创建好多模块的项目了,下 ...

  4. PHP pdf 转 图片

    function pdf2png($pdf,$path,$page=-1) { if(!extension_loaded('imagick')) { return false; } if(!file_ ...

  5. [CF1220C] Substring Game in the Lesson - 博弈论

    [CF1220C] Description 给定一个字符串 \(S\) , 同时维护一个区间 \([l,r]\) .轮流操作,每次可以扩展到一个新区间使得原区间是新区间的真子区间,并且字典序更小,不能 ...

  6. Oracle VM VirtualBox - ping不通虚拟机

    问题描述 用Oracle VM VirtualBox创建虚拟机后,本机电脑ping不通虚拟机 解决方案 https://www.cnblogs.com/ranrongzhen/p/6958485.ht ...

  7. spring boot使用freemarker模版整合spring Data JPA

    目录结构 第一步:在pom.xml文件中添加依赖 <!--模板依赖--> <dependency> <groupId>org.springframework.boo ...

  8. sql注入的原理是什么,怎么预防sql注入

    为什么会产生sql注入: 主要原因,对用户输入的绝对信任,相信所有用户的输入都是可信的,没有对用户输入的语句进行过滤或者筛选,直接放到sql语句中进行拼接,从而导致了sql注入的产生 例如: < ...

  9. Java学习笔记(十一)面向对象---多态

    多态的体现 父类的引用指向了自己的子类对象. 父类的引用也可以接受自己的子类对象. 代码体现 abstract class Animal { public abstract void eat(); } ...

  10. SpringBoot:静态资源的访问和配置(转载)

    默认静态资源访问Spring Boot的默认静态资源的路径为: spring.resources.static-locations=classpath:/META-INF/resources/,cla ...