Trucking

题目连接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2224

Descriptionww.co

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

Hint

题意

有n个城市,m条双向边,每条边有两个限制,1是高度限制,2是花费

然后让你从s到t,高度不超过c的情况下,你最高为多少,保证最高的情况下,花费最小为多少

题解:

二分+spfa,裸题

直接跑就好了,注意输出,两个直接必须有空行,最后一个答案不能有空行

其他就没什么坑点了

代码

#include<bits/stdc++.h>
using namespace std;const int maxn = 1e3+5;
struct node
{int x,y,z;
};
vector<node> E[maxn];
int d[maxn];
queue<int> Q;
int inq[maxn];
int n,m;
int spfa(int a,int b,int c)
{memset(inq,0,sizeof(inq));while(!Q.empty())Q.pop();for(int i=1;i<=n;i++)d[i]=1e9;d[a]=0;Q.push(a);inq[a]=1;while(!Q.empty()){int now = Q.front();Q.pop();inq[now]=0;for(int i=0;i<E[now].size();i++){if(E[now][i].y<c)continue;if(d[E[now][i].x]>d[now]+E[now][i].z){d[E[now][i].x] = d[now]+E[now][i].z;if(!inq[E[now][i].x]){inq[E[now][i].x]=1;Q.push(E[now][i].x);}}}}if(d[b]==1e9)return 0;return 1;
}
int main()
{int cas = 0;while(scanf("%d%d",&n,&m)!=EOF){cas++;if(n==0&&m==0)break;for(int i=1;i<=n;i++)E[i].clear();for(int i=1;i<=m;i++){int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);if(c==-1)c=1e9;node p;p.x=b,p.y=c,p.z=d;E[a].push_back(p);p.x=a;E[b].push_back(p);}int a,b,c;scanf("%d%d%d",&a,&b,&c);int l = 0,r = c;while(l<=r){int mid = (l+r)/2;if(spfa(a,b,mid))l=mid+1;else r=mid-1;}l--;spfa(a,b,l);if(d[b]==1e9){if(cas!=1)printf("\n");printf("Case %d:\n",cas);printf("cannot reach destination\n");}else{if(cas!=1)printf("\n");printf("Case %d:\n",cas);printf("maximum height = %d\n",l);printf("length of shortest route = %d\n",d[b]);}}
}

UVALive 4223 Trucking 二分+spfa相关推荐

  1. poj 2049(二分+spfa判负环)

    poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...

  2. hdu2962 二分 + spfa

    题意:       给你一个无向图,每条路径上都有自己的长度和最大承受高度,给你起点终点还有车的最大承装高度,问你高度最大的前提下路径最短是多少,求高度和路径. 思路:      这种类型题目太多了, ...

  3. 牛客假日团队赛8:F.Telephone Lines(二分+spfa)

    链接:https://ac.nowcoder.com/acm/contest/1069/F 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...

  4. P1948 [USACO08JAN]Telephone Lines S(二分+spfa)

    题目描述 Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is u ...

  5. UVALive - 4223(hdu 2926)

    ---恢复内容开始--- 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS ...

  6. bzoj 1614: [Usaco2007 Jan]Telephone Lines架设电话线(二分+SPFA)

    1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1761  Solve ...

  7. 2019.03.30【NOIP提高组】模拟 B 组 排序、二分+spfa、树形DP+前缀和

    文章目录 0 SERN的野望 1 与机关的决战 2 蜡笔 立阳二中.清华经管系贺朝 0 SERN的野望 Error! Human is dead. Mismatch. SERN妄图研发出时间机器,然而 ...

  8. LibreOJ10082. 「一本通 3.3 例 1」Word Rings【二分+SPFA】

    10082. 「一本通 3.3 例 1」Word Rings [题目描述] 传送门 [题解] 将一个字符串看成一条边,字符两端的字符看成节点,长度看成权值.二分枚举答案,最后SPFA刷正环,因为只要有 ...

  9. 洛谷1462 通往奥格瑞玛的道路 二分+spfa

    题目链接: https://www.luogu.org/problem/show?pid=1462 题意: 题解: 二分法+最短路判定. 二分经过城市的最大费用w,然后判定:对于每一个费用大于w的城市 ...

最新文章

  1. 推荐8款堪称神器的良心软件
  2. 端口偷窃(Port Stealing)技术
  3. mysql为什么没有nvarchar,关于mysql:为什么不将每个VARCHAR指定为VARCHAR(65535)?
  4. Escape The Maze (easy version) 多源最短路,bfs(1700)
  5. oracle数据库更改字符集
  6. Bear and Strings
  7. 传送门(最短路树+可并堆)
  8. matlab 仿真钢琴,用Matlab模拟钢琴的声音
  9. 吉日嘎拉DotNet.BusinessV4.2中的一处bug,及我的修复和扩展
  10. Django--CRM-客户列表展示, 分页
  11. 如何写好简历与迎接面试
  12. C#|图像快速傅立叶变换与反变换
  13. python requests爬网页加速
  14. Android Espresso(四)——RecyclerView
  15. macbook pro键盘按键帽清理,修复手感变差的问题
  16. 智慧物流自动化智能仓储管理架构分析
  17. windows 命令 系统快捷方式
  18. Dynamips路由模拟器使用心得
  19. c语言图形学三角形平移,MFC怎么对所画几何图形进行旋转、填充、放缩???(急用)【...
  20. Vue 删除列表项的淡出动画

热门文章

  1. 计算机系要考英语口语吗,2015年高考英语口语由计算机“打分”,这些细节要注意!...
  2. 快速崛起的物联网世界安全问题
  3. VB 屏幕融化超级恶搞程序代码
  4. VB:将数字转换为大写中文
  5. VB得到指定文件夹下的文件列表
  6. 核能版“水变油”登上Nature!谷歌7000万押注,MIT参与,被评争风加水汽车
  7. 上车,在北京地铁10号线偶遇一下
  8. 如何自制会跳舞的AI小姐姐?这有一份易上手的开源攻略
  9. Facebook要造芯片了,开发团队正在组建中
  10. 吴恩达对话LeCun:神经网络跌宕四十年