F - Trucking

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

 

A certain local trucking company would like to transport some goods on a cargo truck from one place to another. It is desirable to transport as much goods as possible each trip. Unfortunately, one cannot always use the roads in the shortest route: some roads may have obstacles (e.g. bridge overpass, tunnels) which limit heights of the goods transported. Therefore, the company would like to transport as much as possible each trip, and then choose the shortest route that can be used to transport that amount.

For the given cargo truck, maximizing the height of the goods transported is equivalent to maximizing the amount of goods transported. For safety reasons, there is a certain height limit for the cargo truck which cannot be exceeded.

Input

The input consists of a number of cases. Each case starts with two integers, separated by a space, on a line. These two integers are the number of cities (C) and the number of roads (R). There are at most 1000 cities, numbered from 1. This is followed by R lines each containing the city numbers of the cities connected by that road, the maximum height allowed on that road, and the length of that road. The maximum height for each road is a positive integer, except that a height of -1 indicates that there is no height limit on that road. The length of each road is a positive integer at most 1000. Every road can be travelled in both directions, and there is at most one road connecting each distinct pair of cities. Finally, the last line of each case consists of the start and end city numbers, as well as the height limit (a positive integer) of the cargo truck. The input terminates when C = R = 0.

Output

For each case, print the case number followed by the maximum height of the cargo truck allowed and the length of the shortest route. Use the format as shown in the sample output. If it is not possible to reach the end city from the start city, print "cannot reach destination" after the case number. Print a blank line between the output of the cases.

Sample Input

5 6
1 2 7 5
1 3 4 2
2 4 -1 10
2 5 2 4
3 4 10 1
4 5 8 5
1 5 10
5 6
1 2 7 5
1 3 4 2
2 4 -1 10
2 5 2 4
3 4 10 1
4 5 8 5
1 5 4
3 1
1 2 -1 100
1 3 10
0 0

Sample Output

Case 1:
maximum height = 7
length of shortest route = 20 Case 2:
maximum height = 4
length of shortest route = 8 Case 3:
cannot reach destination
题意:lLA给你n个节点(<=1000),节点之间最多一条路,路有长度l和高度限制h,现在一辆卡车准备从起点s到终点t,要求
卡车的高度不得高于H,问卡车能达到终点的最高高度H和此最高高度下的最短路径;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
struct edge{
int to,h,l;
};
vector<edge> G[1005];
int dis[1005],inq[1005]; bool ok(int s,int t,int h)
{
queue<int> q;
MM(dis,inf);
MM(inq,0); q.push(s);
inq[s]=1;
dis[s]=0; while(q.size())
{
int u=q.front();q.pop();inq[u]=0;
for(int i=0;i<G[u].size();i++)
{
edge e=G[u][i];
if(e.h<h) continue;
if(dis[e.to]>dis[u]+e.l)
{
dis[e.to]=dis[u]+e.l;
if(!inq[e.to]) {q.push(e.to);inq[e.to]=1;}
}
}
}
return dis[t]!=inf;
} int main()
{
int n,m,kk=0;
scanf("%d %d",&n,&m);
while(1)
{
if(!(n||m)) break;
for(int i=1;i<=n;i++) G[i].clear();
for(int i=1;i<=m;i++)
{
int u,v,h,l;
scanf("%d%d%d%d",&u,&v,&h,&l);
if(h==-1) h=inf;
G[u].push_back((edge){v,h,l});
G[v].push_back((edge){u,h,l});
}
int s,t,H;scanf("%d%d%d",&s,&t,&H);
int l=0,r=H+1,ansl=inf;
while(r-l>1)
{
int mid=(l+r)/2;
if(ok(s,t,mid)) {l=mid;ansl=dis[t];}
else r=mid;
}
printf("Case %d:\n",++kk);
if(ansl==inf) printf("cannot reach destination\n");
else {
printf("maximum height = %d\n",l);
printf("length of shortest route = %d\n",ansl);
}
scanf("%d%d",&n,&m);if(n||m) printf("\n");
else break;
}
return 0;
}

  分析:代码有毒啊,,,SPFA最坏情况V*E,按理说应该会被卡的,,,,,,还是dijkstra+堆优化比较稳;

分析:很简单的图论题,最大化某个值二分就当然想到了,关键是找路,其实就是在最短路的代码里面,加上一个对

路径边的选择,就是如果当前路径的高度限制<二分枚举的值得话,那么这条路当然不能选择(其实也就是相当于在

原来的图中把限制高度<二分枚举的h边全部擦掉),,简单的一笔,比以前做的图论题简单不知道哪里去了,,比赛

被吓傻了

 

LA 4223 最短路 路径选择要求提高一点的更多相关文章

  1. 辛巴学院-Unity-剑英的c#提高篇(一)主循环

    这是测试版 辛巴学院:正大光明的不务正业. 最近刚刚离开了我服务了三年多的公司,因为一个无数次碰到的老问题,没钱了. 之前不知道做什么好的时候,机缘巧合之下和哒嗒网络的吴总聊了一下,发现了vr gam ...

  2. 最小生成树&最短路基础算法总结

    [最短路问题] 解决最短路问题有以下算法:Dijkstra算法,Bellman-Ford算法,Floyd算法,和SPFA算法和启发式搜索算法A*; 每个算法都有它的特点可以解决某些特定的问题,例如:F ...

  3. 95%的中国网站需要重写CSS

    95%的中国网站需要重写CSS 很长一段时间,我都使用12px作为网站的主要字体大小.10px太小,眼睛很容易疲劳,14px虽容易看清,却破坏页面的美感.唯独12px在审美和视力方面都恰到好处. 谁对 ...

  4. 为IEnumerable<T>添加RemoveAll<IEnumerable<T>>扩展方法--高性能篇

    最近写代码,遇到一个问题,微软基于List<T>自带的方法是public bool Remove(T item);,可是有时候我们可能会用到诸如RemoveAll<IEnumerab ...

  5. JS 的事件委托机制

    以前写上图所示的鼠标点击触发事件,一般都是用如下所示的给每一个表示列表的标签绑定一个click事件(演示用的例子的框架是React): 毫无疑问,这样是比较繁琐的,以后维护修改改个函数名什么的还不方便 ...

  6. ELK+Kafka集群日志分析系统

    ELK+Kafka集群分析系统部署 因为是自己本地写好的word文档复制进来的.格式有些出入还望体谅.如有错误请回复.谢谢! 一. 系统介绍 2 二. 版本说明 3 三. 服务部署 3 1) JDK部 ...

  7. OO Design

    什么是设计原则? 设计原则是基本的工具,应用这些规则可以使你的代码更加灵活.更容易维护.更容易扩展.基本原则:封装变化Encapsulate what varies.面向接口变成而不是实现 Code ...

  8. U盘安装操作系统

    U盘安装操作系统 On 2010 年 4 月 27 日, in IT, by hr 写在前面 本文主要介绍如何使用U盘安装系统,无法使用光驱安装或者不想随身带着光盘,使用这招都很管用,而且备着这样一只 ...

  9. 【转】IE劫持原理 BHO

    为什么"浏览器劫持"能够如此猖狂呢?放眼众多论坛的求助贴,我们不时可以看到诸如"我的IE被主页被改了,我用杀毒工具扫了一遍都没发现病毒,我把主页改回自己的地址,可是一重启 ...

随机推荐

  1. Python编程之注释

    一.注释 当你把变量理解透了,你就已经进入了编程的世界.随着学习的深入,用不了多久,你就可以写复杂的上千甚至上万行的代码啦,有些代码你花了很久写出来,过了些天再回去看,发现竟然看不懂了,这太正常了. ...

  2. 如何修改maven本地仓库位置

    1.创建文件夹D:\m2\repository 2.修改E:\apache-maven-3.5.4\conf\setting.xml文件.将 改成<localRepository>< ...

  3. Jmeter之参数化(4种设置方法)

    以多用户登录为例~~~ 参数化: 1.用户参数 2.CSV数据文件 3.函数助手CSVRead 4.用户自定义的变量 1.用户参数 脚本目录结构如下: 因为设置了2组账号密码,所以线程数设置为2(添加 ...

  4. 服务端相关知识学习(一)之什么是zookeeper

    什么是zookeeper zookeeper是分布式协调服务,可以在分布式系统中共享配置.协调锁资源.提供命名服务那分布式协调服务又是个什么东西呢?首先我们来看“协调”是什么意思.在一个并发的环境里, ...

  5. JS基础_质数练习,用到了标记flag

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. form表单中的enctype 属性以及post请求里Content-Type方式

    对于form表单中的enctype 属性之前理解的一般,就知道是类似于一种编码形式.后来公司做一个form表单提交数据的时候,重点是这个form表单里有文件上传,而我又要用vue来模拟form表单提交 ...

  7. cmake 判断操作系统平台

    转载自 cmake 判断操作系统平台 MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}") IF (CMAKE_SYSTEM_ ...

  8. struct:二进制数据结构的打包与解包

    介绍 struct模块包括一些函数,这些函数可以完成字节串与原生Python数据类型(如数字和字符串)之间的转换 函数与Struct类 struct提供了一组处理结构值的模块级函数,另外还有一个Str ...

  9. 详解python中的生成器表达式

    什么是生成器表达式 还记得列表解析吗?我们把[]换成()就变成生成器表达式了. g = (x for x in [1, 2, 3, 4]) print(g) # <generator objec ...

  10. js动态添加控件(输入框为例)

    写在前面 昨天得到一个需求,需要在账户登记页面中动态添加输入框,经过半天的捣鼓,最终完美成型,写下来跟大家分享下, 供大家参考 开始复制代码了 如果复制了我所有代码的话,注意看js最后面方法的备注,最 ...