网络流问题
网络流是一类关于图中(一般是有向图)的的流的问题。
最大流问题和增广路算法(Edmonds-Karp)
增广路算法是用来求解最大流问题的算法,算法的思想就是:从0开始不断寻找增广路,然后反向增加流量,最终不能增加流量是停止算法,其中使用BFS寻找增广路的叫做Edmonds-Karp算法
struct Edge{
int from,to,cap,flow;
Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f) {
}
};
struct EdmondsKarp{
int n,m;
vector<Edge> edges; //边数的两倍
vector<int> G[maxn]; //邻接表,G[i][j]表示节点i的第j条边在e数组中的序号
int a[maxn]; //当起点到点i的改进量
int p[maxn]; //最短路树上的p的入弧编号
void init(int n){
for(int i=0;i<n;++i) G[i].clear();
edges.clear();
}
void AddEdge(int from,int to,int cap){
edges.push_back(Edge(from,to,cap,0));
edges.push_back(Edge(to,from,0,0)); //反向弧
m=edge.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
}
int Maxflow(itn s,int t){
in