"Shortest" pair of paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1407   Accepted: 627 Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There ar…
[题目链接] http://poj.org/problem?id=3068 [题目大意] 给出一张图,要把两个物品从起点运到终点,他们不能运同一条路过 每条路都有一定的费用,求最小费用 [题解] 题目等价于求两条无交叉最短路,可用流量为2的费用流求解 [代码] #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; con…
[原题](http://poj.org/problem?id=3068) 给一个有向带权图,求两条从0-N-1的路径,使它们没有公共点且边权和最小 . //是不是像传纸条啊- 是否可行只要判断最后最大流是不是2就可以了 #include<cstdio> #include<queue> #include<cstring> #define N 1010*1010 #define inf 0x3f3f3f3f using namespace std; int n,m,head…
"Shortest" pair of paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1589 Accepted: 708 Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There are M…
POJ3068 "Shortest" pair of paths Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There are M individual shipping methods (edges) connecting pairs of depots. Each i…
"Shortest" pair of paths 题目大意 给出 \(n\) 个点,\(m\) 条边,除第一个点和最后一个点外,其他所有的点都只能被经过一次,要求找到两条从第一个点到最后一个点的路径,使其长度和最小. 分析 拿到这道题,通过观察数据范围和问题模式,其实很容易想到这是一道可以通过网络流来解决的问题,网络流确实非常擅长通过连边的流量限制来表示这种对经过次数的限制. 本题就是一个非常明显的最小费用流,其建图套路也比较容易想到: 拆点,将每个点拆成入点和出点,除了第一个点与最后…
[题目链接] http://poj.org/problem?id=3686 [题目大意] 每个工厂对于每种玩具的加工时间都是不同的, 并且在加工完一种玩具之后才能加工另一种,现在求加工完每种玩具的平均时间 [题解] 因为每个工厂加工一个零件在不同的时间是有不同代价的, 我们发现对于一个工厂在每次加工一个零件时候,时间要加上之前所有的零件的时间的条件 其实等价于对这个工厂加工的零件乘上1~N的不同系数. 那么我们将这个工厂对于时间进行拆点,对于费用乘上不同的系数,求一遍费用流即可 [代码] #in…
题目链接 给一个n*n的矩阵, 从左上角出发, 走到右下角, 然后在返回左上角,这样算两次. 一共重复k次, 每个格子有值, 问能够取得的最大值是多少, 一个格子的值只能取一次, 取完后变为0. 费用流第一题, 将每个格子拆为两个点, u向u'连一条容量为1, 费用为格子的值的边, u向u'再连一条容量为k-1, 费用为0的边.u'向他右边和下边的格子连一条容量为k, 费用为0的边, 跑一遍费用流就可以. #include <iostream> #include <vector>…
Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3408   Accepted: 1513 Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must…
嘟嘟嘟 题目大意:一个有向图,每一条边有一个边权,求从节点\(0\)到\(n - 1\)的两条不经过同一条边的路径,并且边权和最小. 费用流板子题. 发个博客证明一下我写了这题. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> #include<cstdlib> #include<cctype>…