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. maven私服的项目使用配置

    环境:  eclipse .maven.nexus. 1.配置setting.xml文件 1.1.配置本地仓库位置:文件中,存在节点 “localRepository”,默认是注释,也就是本地仓库使用 ...

  2. sqlldr - exit error code 2 in unix (merged)

    http://www.orafaq.com/forum/t/146582/ Thank you for your reply. Load has been successful all the tim ...

  3. JS中的call()和apply()方法(转)

    转自:http://uule.iteye.com/blog/1158829 JS中的call()和apply()方法 博客分类: JS   1.方法定义 call方法: 语法:call([thisOb ...

  4. docker-ce 搭建的 lamp 开发环境笔记

    工作目录: /home/{username}/dockers/lamp 将docker容器的apache的80 映射为本地主机的81 # sudo docker pull mattrayner/lam ...

  5. typedef 函数指针的使用(含例子)

    C代码   //#include<iostream.h>   #include<stdio.h>      typedef int (*FP_CALC)(int, int);  ...

  6. JavaSE---类、对象、成员变量、局部变量

    1.概述 1.1 类 1.1.1 类   是一种  自定义的  引用  数据类型: 1.2 对象 1.2.1 创建对象的根本途径:构造器: 通过new关键字   来调用  某个类的构造器: packa ...

  7. Vue项目中使用Vux

    最近想用vue+vux写一个项目,于是到vux的官网看了文档开始着手搭建项目,但是遇到一些坑.下面简单说下安装vux 的过程.默认已安装vue环境1.安装vux npm install vux --s ...

  8. 纯js的右下角弹窗

    <html> <head> <title></title> <meta charset="UTF-8"> <scr ...

  9. jmeter 基础介绍

    Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试,但后来扩展到其他测试领域.它可以用于对静态的和动态的资源(文件,Se ...

  10. nodejs在Windows 7上的搭建

    一.安装nodejs 去官网下载https://nodejs.org/download/,我选择下载node-v9.3.0-x64.msi ,最新版本, 安装路径放在了D盘,因为C盘的空间不够了,直接 ...