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的更多相关文章

  1. CSU 1506 Double Shortest Paths

    1506: Double Shortest Paths Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 49  Solved: 5 Description ...

  2. TZOJ 4712 Double Shortest Paths(最小费用最大流)

    描述 Alice and Bob are walking in an ancient maze with a lot of caves and one-way passages connecting ...

  3. CSU 1506 Problem D: Double Shortest Paths(最小费用最大流)

    题意:2个人从1走到n,假设一条路第一次走则是价值di,假设第二次还走这条路则须要价值di+ai,要你输出2个人到达终点的最小价值! 太水了!一条边建2次就OK了.第一次价值为di,第二次为ai+di ...

  4. Shortest Paths

    最短路径 APIs 带权有向图中的最短路径,这节讨论从源点(s)到图中其它点的最短路径(single source). Weighted Directed Edge API 需要新的数据类型来表示带权 ...

  5. Codeforces 1005 F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...

  6. Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...

  7. 【例题收藏】◇例题·II◇ Berland and the Shortest Paths

    ◇例题·II◇ Berland and the Shortest Paths 题目来源:Codeforce 1005F +传送门+ ◆ 简单题意 给定一个n个点.m条边的无向图.保证图是连通的,且m≥ ...

  8. CF Gym 102028G Shortest Paths on Random Forests

    CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...

  9. All shortest paths between a set of nodes

    .big{font-size:larger} .small{font-size:smaller} .underline{text-decoration:underline} .overline{tex ...

随机推荐

  1. SpringBoot-SpringCloud-版本对应关系

    刚开始研究SpringCloud和SpringBoot的时候,困惑点比较多,SpringBoot是从1.X.X到目前的2.X.X版本,但是SpringCloud基于SpringBoot,版本之间肯定是 ...

  2. 【学习总结】Python-3- 类型判断之 isinstance 和 type 的区别

    菜鸟教程-Python3-基本数据类型 关于类型查询: type() 函数:可以用来查询变量所指的对象类型 用 isinstance()函数:判断是否是某个类型 两者的区别: type()不会认为子类 ...

  3. go中字符类型的使用小结

    示例 // 字符类型的用法 package main import ( "fmt" "unsafe" ) func main() { // 未指定类型并赋值字符 ...

  4. rsync nfs 实时同步,结合实战

    目录 rsync nfs 实时同步,实战 一.部署rsync服务端(backup) 二.部署rsync客户端(nfs,web01) 三.部署web代码(web01) 四.NFS服务端部署(nfs) 五 ...

  5. SessionFactory是线程安全的吗?Session是线程安全的吗?两个线程能共享一个Session吗?

    (1)SessionFactory对应Hibernate的一个数据存储的概念,它是线程安全的,可以被多个线程并发访问.SessionFactory一般只会在启动的时候构建.对于应用程序,最好将Sess ...

  6. vue-router中的router-link的active-class

    vue-router中的router-link的active-class   在vue-router中要使用选中样式的方法有两种: 1.直接在路由js文件中配置linkActiveClass 2.在r ...

  7. solrconfig.xml主要配置项

    solrconfig.xml中的配置项主要分以下几大块: 1.依赖的lucene版本配置,这决定了你创建的Lucene索引结构,因为Lucene各版本之间的索引结构并不是完全兼容的,这个需要引起你的注 ...

  8. Spring整合Struts2的两种方式

    https://blog.csdn.net/cuiyaoqiang/article/details/51887594

  9. mqtt发送消息,消息体为16进制

    在idea 加入代码  :-server -XX:PermSize=256M -XX:MaxPermSize=256M -Dfile.encoding=UTF-8

  10. Vue.js(七)

    ES6 默认导出(只能一次)与默认导入 默认导出: // 当前文件模块为 test.js // 定义私有成员 a 和 c let a = 10 let c = 20 // 外界访问不到变量 d ,因为 ...