#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define min(a,b)(a<b?a:b)
#define INF 0x0fffffff
using namespace std;
#define MAX_V 1000
struct edge
{
int to,cap,rev; //rev代表反向边的to。G[e.to][e.rev]
edge(){}
edge(int a,int b,int c):to(a),cap(b),rev(c){}
};
vector<edge>G[MAX_V];
int level[MAX_V]; //分层
int iter[MAX_V]; ///当前弧,在它之前的边已经不需要再搜索
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;
level[s]=0;
que.push(s);
while(!que.empty())
{
int v=que.front();
que.pop();
int i;
for(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==t)
return f;
for(int &i=iter[v];i<G[v].size();i++)
{
edge &e=G[v][i];
if(e.cap>0&&level[v]<level[e.to])
{
int d=dfs(e.to,t,min(f,e.cap));
if(d>0)
{
e.cap-=d;
G[e.to][e.rev].cap+=d;
return d;
}
}
}
return 0;
}
int max_flow(int s,int t)
{
int flow=0;
while(1)
{
bfs(s);
if(level[t]<0)
return flow;
memset(iter,0,sizeof(iter));
int f;
while((f=dfs(s,t,INF))>0)
flow+=f;
}
}
int main()
{
}