#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int maxn=10010;
struct edge{
int to,cap,rev;
};
vector<edge>G[maxn];
int level[maxn];
int iter[maxn];
void add_edge(int from,int to,int cap){
G[from].push_back((edge){to,cap,G[to].size()});
G[to].push_back((edge){from,0,G[from].size()-1});
}
void bfs(int s){
memset(level, -1, sizeof(level));
queue<int> que;
que.push(s);
while(!que.empty()){
int v=que.front();
que.pop();
for(int i=0;i<G[v].size();i++){
edge &e=G[v][i];
if(e.cap>0&&level[e.to]<0){
level[e.to]=level[v]+1;
que.push(e.to);
}
}
}
}
int dfs(int v,int t,int f){
if(v==f) return f;
for(int &i=iter[v];i<G[v].size();i++){
edge &e=G[v][i];
if(e.cap>0&&level[e.to]>level[v]){
int d=dfs(e.to,t,min(f,e.cap));
e.cap-=d;
G[e.to][e.rev].cap+=d;
return d;
}
}
return 0;
}
int max_flow(int s,int t){
int flow=0;
for(;;){
bfs(s);
if(level[s]<0) return flow;
memset(iter, 0,sizeof(iter));
int f;
while ((f=dfs(s,t,1000000))>0) {
flow+=f;
}
}
}
08-27
537
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-21
2218
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-21
2207
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-21
2076
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)