Edmonds-Karp最大流算法使用方法及示例程序
Edmonds-Karp算法是最大流算法中的一种,与Ford-Fulkerson算法类似,都采用增广路思想。不同之处在于,Edmonds-Karp算法利用广度优先搜索来寻找增广路径,保证了时间复杂度为O(VE^2),是一种可行且高效的最大流算法。
本文将介绍Edmonds-Karp算法的使用方法,并附上一个简单的测试程序,供读者参考。
示例代码:
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 110, M = (int)(1e6), INF = (int)(1e9);
int s, t, n, m, h[N], e[M], f[M], ne[M], idx;
int d[N], pre[N], incf[N];
void add(int a, int b, int c)
{
e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
e[idx] = a, f[idx] = 0, ne[idx] = h[b], h[b] = idx ++ ;
}
bool bfs()
{