Evacuation Plan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4914   Accepted: 1284   Special Judge Description The City has a number of municipal buildings and a number of fallout shelters that were build specially to hide municipal w…
POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the b…
题目:id=2135" target="_blank">poj 2135 Farm Tour 题意:给出一个无向图,问从 1 点到 n 点然后又回到一点总共的最短路. 分析:这个题目不读细致的话可能会当做最短路来做,最短路求出来的不一定是最优的,他是两条分别最短,但不一定是和最短. 我们能够用费用流来非常轻易的解决,建边容量为1,费用为边权.然后源点s连 1 .费用0 .容量 2 ,n点连接汇点,容量2,费用0,,就能够了. 注意这个题目是无向图,所以要建双向边. AC…
/** 题目:hdu3667 Transportation 拆边法+最小费用最大流 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3667 题意:n个城市由m条有向边连接.要从城市1运输k流量到城市n.每条边有可以运输的流量容量,以及费用系数ai. 费用系数指该条边的费用为该条边的运输流量x的平方乘以ai.即ai*x^2. 如果无法运输k流量,输出-1,否则输出从城市1运输k流量到城市n的最小花费. 思路:拆边法+最小费用最大流 假设从u->v 容量为…
Farm Tour Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 2135 64-bit integer IO format: %lld      Java class name: Main   When FJ's friends visit him on the farm, he likes to show them around. His farm compr…
题目大意: 给你一个n个农场,有m条道路,起点是1号农场,终点是n号农场,现在要求从1走到n,再从n走到1,要求不走重复路径,求最短路径长度. 算法讨论: 最小费用最大流.我们可以这样建模:既然要求不能走重复路,就相当于每条边的容量是1,我们只可以单向流过容量为1的流量.但是要注意,对于每一条边来说, 它可能是去路的边,也可能是回路的边,所以这个图是个无向图.在加边的时候,两个方向的边都要加.所以要加两组的边,流量为1像正常一样加边就可以了. 然后我们考虑,求这个“环”就是相当于求从1..N的两…
Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the big barn. A total M (1 <= M <…
POJ 3422 Kaka's Matrix Travels 链接:http://poj.org/problem? id=3422 题意:有一个N*N的方格,每一个方格里面有一个数字.如今卡卡要从左上角走到右下角,规定每次仅仅能向下或者向右走.每次走到一个格子,将得到该格子的数字,而且该格子的数字变为0.当卡卡走一次时,非常easy求出最大值,问卡卡走k次,可以得到的最大值为多少. 思路:最小费用最大流 关键是怎样构图 1. 将N*N个格点拆分为两个点(i,i + N*N),每一个点之间连一条流…
[题目链接] http://poj.org/problem?id=2135 [题目大意] 有一张无向图,求从1到n然后又回来的最短路 同一条路只能走一次 [题解] 题目等价于求从1到n的两条路,使得两条路的总长最短 那么就等价于求总流量为2的费用流 [代码] #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #i…
两条路不能有重边,既每条边的容量是1.求流量为2的最小费用即可. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include…