题目传送门 /* 最小费用流:KM算法是求最大流,只要w = -w就可以了,很经典的方法 */ #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; int x[MAXN], y[MAXN]; int w[MAXN][MAXN]; int visx[MAXN],…
题目传送门 /* KM:裸题第一道,好像就是hungary的升级版,不好理解,写点注释 KM算法用来解决最大权匹配问题: 在一个二分图内,左顶点为X,右顶点为Y,现对于每组左右连接Xi,Yj有权w(i,j), 求一种匹配使得所有w(i,j)的和最大.也就是最大权匹配一定是完备匹配.如果两边的点数相等则是完美匹配. 如果点数不相等,其实可以虚拟一些点,使得点数相等,也成为了完美匹配.最大权匹配还可以用最大流去解决 */ #include <cstdio> #include <algorit…
题目传送门 /* KM: 相比HDOJ_1533,多了重边的处理,还有完美匹配的判定方法 */ #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; int x[MAXN], y[MAXN]; int w[MAXN][MAXN]; int visx[MAXN],…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 5111    Accepted Submission(s): 2385 Problem Description Network flow is a well-kn…
Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20754   Accepted: 10872 Description A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount…
#include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; + ; const int INF = 0x7FFFFFFF; struct Edge { int from, to, cap, flow;…
EK算法: int fir[maxn]; int u[maxm],v[maxm],cap[maxm],flow[maxm],nex[maxm]; int e_max; int p[maxn],q[maxn],d[maxn]; void add_edge(int _u,int _v,int _w) { int e; e=e_max++; u[e]=_u;v[e]=_v;cap[e]=_w; nex[e]=fir[u[e]];fir[u[e]]=e; e=e_max++; u[e]=_v;v[e]=…
/* Time:2015-6-18 接触网络流好几天了 写的第一个模版————Ford-Fulkerson算法 作用:求解网络最大流 注意:源点是0 汇点是1 如果题目输入的是1到n 请预处理减1 */ #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> using namespace std; const int INF =…
增广路的核心就是引入了反向边,使在进行道路探索选择的时候增加了类似于退路的东西[有一点dp的味道??] 具体操作就是:1.首先使用结构体以及数组链表next[ MAXN ]进行边信息的存储 2.[核心]在存储正向边时,将正向边结构体数组相邻编号的元素存储反向边 [具体操作:如正向边为AA[0],则对应的反向边为AA[1],这样就可以在之后通过异或来对正向边对应的反向边进行更新][初始时反向边的容量为0] 3.通过dfs进行寻路,寻路过程要用数组记录下来路经过的边的编号,便于在找到终点后遍历找边的…
题目链接. 分析: 网络流增广路算法模板题.http://www.cnblogs.com/tanhehe/p/3234248.html AC代码: #include <iostream> #include <queue> #include <cstdio> #include <cstring> using namespace std; ; <<); int cap[maxn][maxn], flow[maxn][maxn]; int n; int…