Travel in desert
不算难吧
应该有思路的
还是太水了吧
(而且和货车运输很像的啊
----------------------------------------------------------------------------------------
题目大意
沙漠中有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的更多相关文章
- 【UVA10816】Travel in Desert (最小瓶颈路+最短路)
UVA10816 Travel in Desert 题目大意 沙漠中有一些道路,每个道路有一个温度和距离,要求s,t两点间的一条路径,满足温度最大值最小,并且长度最短 输入格式 输入包含多组数据. 每 ...
- 【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)
[题意] 有n个绿洲, m条道路,每条路上有一个温度,和一个路程长度,从绿洲s到绿洲t,求一条道路的最高温度尽量小, 如果有多条, 选一条总路程最短的. InputInput consists of ...
- uva 10816 Travel in Desert(简单的好题~两种方法)
题意: 给出 一个图 点与点之间的路径上有两个权值 路径长度和温度 要求在所走路径中的温度的最大值最小的前提下 走最短路径 解题思路1: 首先用 最小生成树 的方法走出 最小瓶颈路 .把在这期间用到的 ...
- UVA-10816 Travel in Desert (最小瓶颈最短路)
题目大意:给一张无向图,图中的每条边都有两个权值,长度d和热度r.找出从起点到终点的一条最大热度最小的路径,如果这样的路径有多条,选择一个最短的. 题目分析:如果只考虑最小的最大热度,那么本题就是一个 ...
- 图论 - Travel
Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...
- 【BZOJ-1576】安全路径Travel Dijkstra + 并查集
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1044 Solved: 363[Sub ...
- Linux inode && Fast Directory Travel Method(undone)
目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...
- HDU - Travel
Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
随机推荐
- 洛谷P1170 兔八哥与猎人 欧拉函数的应用
https://www.luogu.org/problem/P1170 #include<bits/stdc++.h> using namespace std; ],b[],c[],d[] ...
- 洛谷P1042 乒乓球
https://www.luogu.org/problem/P1042 #include<bits/stdc++.h> using namespace std; ]; int w,l; i ...
- numpy基础知识练习
# 1.导入numpy模块 # 2.创建一个大小为10的空向量 # 3.创建一个大小为10的空向量,但是第五个值为1 # 4.创建一个10-49的ndarray数组 # 5.创建一个3x3的矩阵,其值 ...
- Go_go build 和 go install
1.作用 go build:用于测试编译包,在项目目录下生成可执行文件(有main包). go install:主要用来生成库和工具.一是编译包文件(无main包),将编译后的包文件放到 pkg 目录 ...
- hrtf virtual surround matlab实现
将5.1 ch的数据经过hrtf处理,然后downmix到2ch,使得2ch的数据有virtual surround的效果. function output = hrir_process(input) ...
- SSL扫描工具
工具: sslciphercheck sslscan sslciphercheck.exe -h ip -p 443 有些IP会报错:
- sendmail邮件服务器
安装sendmail之前 我们要先搭建一个DNS服务器用来解析邮件 下图是配置好的DNS正向解析记录和反向解析记录 正向 反向 DNS配置好之后我们就来安装sendmail服务 然后再安装sendma ...
- MANIFEST.MF详解及配置的注意事项
一.详解 打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录, 这个目录下会有一些文件,其中必有一个MANIFEST.MF,这个文件描述了该Jar文件的很多信息,下面将详细介 ...
- 交叉连接(CROSS JOIN)
除了在FROM子句中使用逗号间隔连接的表外,SQL还支持另一种被称为交叉连接的操作,它们都返回被连接的两个表所有数据行的笛卡尔积,返回到的数据行数等于第一个表中符合查询条件的数据行数乘以第二个表中符合 ...
- c++中sort函数调用报错Expression : invalid operator <的内部原理 及解决办法
转自:https://www.cnblogs.com/huoyao/p/4248925.html 当我们调用sort函数进行排序时,中的比较函数如果写成如下 bool cmp(const int &a ...