#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int int_max = 0x07777777;
const int int_min = 0x80000000;
const int maxn = 5000;
struct Edge{
int from, to, cap, flow;
Edge(int _from, int _to, int _cap, int _flow):from(_from),to(_to),cap(_cap),flow(_flow){}
};
vector<Edge> es;
vector<int> g[maxn];
int result,s,t;
int p[maxn],a[maxn];
void addedge (int from, int to, int cap){
es.push_back(Edge(from, to, cap, 0));
es.push_back(Edge(to, from, 0,0));
int num = es.size();
g[from].push_back(num-2);
g[to].push_back(num-1);
}
void solve (){
result = 0;
while (true) {
memset(a, 0, sizeof(a));
a[s] = int_max;
queue<int> q;
q.push(s);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = 0; i < g[u].size(); i++){
Edge& e = es[g[u][i]];
if(!a[e.to] && e.cap > e.flow){
a[e.to] = (a[e.from] > e.cap-e.flow ? e.cap-e.flow : a[e.from]);
p[e.to] = g[u][i];
q.push(e.to);
}
}
}
if(!a[t]) break;
result += a[t];
int u = t;
while(u!=s){
es[p[u]].flow += a[t];
es[p[u]^1].flow -= a[t];
u = es[p[u]].from;
}
}
}
最大流模板
最新推荐文章于 2020-01-31 22:24:43 发布