UVA 12821 Double Shortest Paths
Double Shortest Paths
Alice and Bob are walking in an ancient maze with a lot of caves and one-way passages connecting
them. They want to go from cave 1 to cave n. All the passages are difficult to pass. Passages are too
small for two people to walk through simultaneously, and crossing a passage can make it even more
difficult to pass for the next person. We define di as the difficulty of crossing passage i for the first time,
and ai as the additional difficulty for the second time (e.g. the second person’s difficulty is di + ai).
Your task is to find two (possibly identical) routes for Alice and Bob, so that their total difficulty
is minimized.
For example, in figure 1, the best solution is 1 → 2 → 4 for both Alice and Bob, but in figure 2, it’s
better to use 1 → 2 → 4 for Alice and 1 → 3 → 4 for Bob. It’s always possible to reach cave n
from cave 1.
Input
There will be at most 200 test cases. Each case begins with two integers n, m (1 ≤ n ≤ 500, 1 ≤
m ≤ 2000), the number of caves and passages. Each of the following m lines contains four integers u,
v, di and ai (1 ≤ u, v ≤ n, 1 ≤ di ≤ 1000, 0 ≤ ai ≤ 1000). Note that there can be multiple passages
connecting the same pair of caves, and even passages connecting a cave and itself.
Output
For each test case, print the case number and the minimal total difficulty.
Sample Input
4 4
1 2 5 1
2 4 6 0
1 3 4 0
3 4 9 1
4 4
1 2 5 10
2 4 6 10
1 3 4 10
3 4 9 10
Sample Output
Case 1: 23
Case 2: 24
这是偶做的一条MCMF。
一开始想dij一次最短路。然后用dfs再记录下来。然后换路。在dij一次。
然后发现这样有可能是错的 。。 因为用一种情况是 2 次都经过了 最短路的一部分 。
。 是有可能小于走完整条最短路 ,然后再多走一次最短路的。。。
例如 。。
后来州神给出来一个样例。

然而, u ,v 构一条费用为 w 流量为1 。一条为w + a ,流量也为1的边
然后源和汇到1 , n的费用为0,流量为2 , 求出来就是才是真正的答案 ...
UVA 12821 Double Shortest Paths的更多相关文章
- CSU 1506 Double Shortest Paths
1506: Double Shortest Paths Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 49 Solved: 5 Description ...
- TZOJ 4712 Double Shortest Paths(最小费用最大流)
描述 Alice and Bob are walking in an ancient maze with a lot of caves and one-way passages connecting ...
- CSU 1506 Problem D: Double Shortest Paths(最小费用最大流)
题意:2个人从1走到n,假设一条路第一次走则是价值di,假设第二次还走这条路则须要价值di+ai,要你输出2个人到达终点的最小价值! 太水了!一条边建2次就OK了.第一次价值为di,第二次为ai+di ...
- Shortest Paths
最短路径 APIs 带权有向图中的最短路径,这节讨论从源点(s)到图中其它点的最短路径(single source). Weighted Directed Edge API 需要新的数据类型来表示带权 ...
- Codeforces 1005 F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...
- Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...
- 【例题收藏】◇例题·II◇ Berland and the Shortest Paths
◇例题·II◇ Berland and the Shortest Paths 题目来源:Codeforce 1005F +传送门+ ◆ 简单题意 给定一个n个点.m条边的无向图.保证图是连通的,且m≥ ...
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- All shortest paths between a set of nodes
.big{font-size:larger} .small{font-size:smaller} .underline{text-decoration:underline} .overline{tex ...
随机推荐
- uWSGI、WSGI、uwsgi、wsgiref、werkzeug
WSGI WSGI:全称是Web Server Gateway Interface,WSGI不是服务器,也不是python模块.框架.API或者任何软件,只是一种规范,描述web server如何与w ...
- python学习第二天--字符串及格式化输出
# 字符串# 字符串取值:字符串名[索引值] 只能取单个值# 正序访问,从0开始str1 = "hello world"print(str1[3]) # 输出"l&quo ...
- python字符串有多少字节
是否有一些函数可以告诉我字符串在内存中占用多少字节? 我需要设置套接字缓冲区的大小,以便一次传输整个字符串. 解决方案 import sys sys.getsizeof(s) # getsizeof( ...
- hdu1158 Employment Planning(dp)
题目传送门 Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- Docker 在 centos 7上升级
Docker 在 centos 7上升级 狂暴的蚂蚁 关注 2017.05.22 10:49* 字数 194 阅读 3253评论 0喜欢 1 引子 如果有旧的Docker 先删除 旧Docker版本上 ...
- Linux系统安全
简单优化: 1.删除不必要的软件包(如postfix等) yum remove -y postfix 安装管理:1.口令 1.1至少8个字符,大小写.特殊字符和数字组合,定期更改 1.2口令长度可以编 ...
- webpack插件之html-webpack-plugin
官方文档:https://www.npmjs.com/package/html-webpack-plugin html-webpack-plugin 插件专门为由webpack打包后的js提供一个载体 ...
- Delphi ini文件结构简介
一.INI文件的结构:; 注释[小节名]关键字=值 INI文件允许有多个小节,每个小节又允许有多个关键字, “=”后面是该关键字的值. 值的类型有三种:字符串.整型数值和布尔值.其中字符串存贮在INI ...
- 【JVM】Java 8 中的常量池、字符串池、包装类对象池
1 - 引言 2 - 常量池 2.1 你真的懂 Java的“字面量”和“常量”吗? 2.2 常量和静态/运行时常量池有什么关系?什么是常量池? 2.3 字节码下的常量池以及常量池的加载机制 2.4 是 ...
- Delphi RegisterHotKey 设置系统热键
Symbolic constant name Value (hexadecimal) Keyboard (or mouse) equivalent VK_LBUTTON 01 Left mouse b ...