费用流模板
spfa不停找当前从s到t的最小费用路,然后刷新最大流
这里把每条边的cost为0,同样就可以求最大流,不过有点慢
#include <cstdio>
#include <cstring>
#include <cctype>
#include <stdlib.h>
#include <string>
#include <map>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
const int N=5000+20;
const int M=50000+20;
int top;//当前边下标
int dis[N],pre[N];//源点到点i的最小距离,pre[i]记录前驱
bool vis[N];//标记数组
int c[N];//入队次数
int maxflow;
struct vertex
{
int first;
} V[N];
struct Edge
{
int v,next;
int cap,flow,cost;
} E[M*2];
void init()
{
mem(V,-1);
top=0;
maxflow=0;
}
void add_edge(int u,int v,int c,int cost)
{
E[top].v=v;
E[top].cap=c;
E[top].flow=0;