今天刚接触最小费用流 码下两个版本当作模板用吧 spfa的做法明天再整理
有负权边的情况只能用Bellman-Ford 没有的话就用Dijkstra 毕竟Dijkstra效率更高
首先贴下Bellman-Ford 实现最小费用流的算法 时间复杂度为 O(FEV) F E V 分别代表需要传输的流量 边的条数 节点的个数
// Bellman_Ford
//Bellman—Ford算法
//Bellman算法求最短增广路&最小费用流 O(FEV)
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<stack>
#include<queue>
#include<cmath>
#include<stack>
#include<list>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
#define MV 11000 //顶点的最大个数
#define INF 0x3f3f3f3f
struct edge
{
int t, cap, cost, rev;
edge(int to = 0, int c = 0, int ct = 0, int r = 0): t(to), cap(c), cost(ct), rev(r) {};
};
vector <edge> G[MV];
int dis[MV];//the distance from source
int prevv[MV], preve[MV];//the previous node and