最大流-EK
来源:互联网 发布:微店网络似乎存在问题 编辑:程序博客网 时间:2024/06/06 16:32
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespacestd;
const int maxn =205;
const int INF =1 << 20;
struct edge{
int u,v,cap,flow;
edge(int u,int v,int cap,int flow) : u(u),v(v),cap(cap),flow(flow) {}
};
struct EdmonsKarp{
int e,v;
vector<int> mp[maxn];
vector<edge> es;
int path[maxn];
int aug[maxn];
void init()
{
for (int i =1; i <= v; i ++) {
mp[i].clear();
}
es.clear();
memset(path,0, sizeof(path));
}
void addedge(int u,int v,int c)
{
es.push_back(edge(u,v,c,0));
es.push_back(edge(v,u,0,0));
int num =es.size();
mp[u].push_back(num -2);
mp[v].push_back(num -1);
}
int maxflow(int s,int t)// 1 m
{
int flow =0;
for(;;){
memset(aug,0, sizeof(aug));
queue<int> q;
q.push(s);
aug[s] =INF;
while (!q.empty()) {//bfs
int x = q.front();
q.pop();
for (int i =0; i < mp[x].size(); i ++) {
edge &e =es[mp[x][i]];
if(!aug[e.v] && e.cap > e.flow)
{
path[e.v] =mp[x][i];
aug[e.v] =min(aug[x],e.cap - e.flow);
q.push(e.v);
}
}
if (aug[t])break;
}
if (!aug[t])break;
for (int i = t; i != s; i =es[path[i]].u) {
es[path[i]].flow += aug[t];
es[path[i] ^1].flow -=aug[t];
}
flow += aug[t];
}
return flow;
}
};
int main()
{
int n,m;//E V
while (cin >> n >> m) {
int a,b,c;
EdmonsKarp ek;
for (int i =0; i < n; i ++) {
scanf("%d%d%d",&a,&b,&c);
ek.addedge(a,b,c);
}
printf("%d\n",ek.maxflow(1, m));
}
return0;
}
- 最大流EK算法
- 最大流EK算法
- 最大流(EK)
- 【POJ1459】【最大流】【EK】
- 【最大流EK】
- 最大流EK
- 最大流-EK
- 最大流-EK算法
- 最大流-EK算法
- poj 1273 EK 最大流
- 最大流EK算法模板
- 最大流 EK算法详解
- 最大流(EK)--poj1149
- hdu1532 最大流 EK算法
- poj1149 PIGS --- 最大流EK
- 图论 最大流EK算法
- 最大网络流 EK 算法
- 最大流之EK算法
- 插入排序(Insertion sort)
- JSON 解析--JObject
- 个人原创
- bitbucket 上传仓库问题记录。
- LintCode高级数据结构/Trie/并查集/搜索题总结
- 最大流-EK
- 旋转数组的最小数字
- Educational Codeforces Round 20 G. Periodic RMQ Problem(线段树+主席树)
- 你永远不会被夺走的东西是什么?认知0002
- 矩阵覆盖
- SVM
- Cross validation/ test set
- 第26课:电光石火间从根本上理解Spark中Sort-Based Shuffle产生的内幕及其tungsten-sort 背景解密
- C++学习笔记