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. LeetCode6 dp

    120. Triangle 我的解法用了一个二维数组,这样比较浪费空间.O(n*n) 但是标准答案自底向上,一是不需要进行特别判断,二是可以覆盖数组,则只需要O(n)的空间大小. class Solu ...

  2. this关键字与super关键字区别

        this super 1 访问属性 访问本类中属性,如果本类中没有此属性,就从父类继承过来的属性中查找 (遵循就近原则) 访问父类中的属性 2 调用方法 访问本类中方法 直接访问父类中方法 3 ...

  3. seaweedfs使用记录

    搭建seaweedfs 在github上面clone,然后cd到docker目录使用docker-compose up -d就可以启动seaweedfs 启动以后通过xxx:9333可以看到效果 上传 ...

  4. Centos7 安装vscode

    1.官网下载vscode https://vscode.cdn.azure.cn/stable/0f3794b38477eea13fb47fbe15a42798e6129338/code-1.36.0 ...

  5. VIM编辑器使用及插件配置

    1.VIM的三种模式: 普通模式.插入模式.命令行模式2.三种模式的转换: 2.1进入普通模式 ①打开VIM默认为普通模式 ②处于插入模式/命令行模式时,按ESC进入普通模式 2.2进入插入模式: A ...

  6. [Java 教程 04] Java基础语法

    在上一篇文章中我们已经运行了个简单的java程序,但是没有给大家讲解代码部分的内容与含义.学习,我们要做到知其然而知其所以然,所以本篇文章我们就来讲解java程序的基本语法,学完这篇文章你再回头看上篇 ...

  7. Hadoop伪分布式环境安装

    一.环境准备 阿里云ECS(Centos7).已预装JDK8 Hadoop安装包 hadoop-2.7.7.tar.gz 二. 安装步骤 1.确认JDK环境的安装位置 命令 echo $JAVA_HO ...

  8. js常用算术运算符与一元运算符在做运算时不同类型的转换规则

    /** * 算术运算符:+, -, *, /, % * 当对非number类型的值进行运算(-, *, /, %)时,会将这些值先转换成number再运算,加法'+'运算除外, * 当对非number ...

  9. 2018-8-10-win10-uwp-httpClient-登陆CSDN

    title author date CreateTime categories win10 uwp httpClient 登陆CSDN lindexi 2018-08-10 19:16:53 +080 ...

  10. shell内置命令getopts