#define MAX_V 1111
struct edge{
int to;
LL cap;
int rev;
};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,LL cap){
edge e;
//(egde){to,cap,G[to].size()}
e.to=to;e.cap=cap;e.rev=G[to].size();
G[from].push_back(e);
//(egde){from,0,G[from].size()-1}
e.to=from;e.cap=0;e.rev=G[from].size()-1;
G[to].push_back(e);
}
void bfs(int s){
int v,i;
memset(level,-1,sizeof(level));
queue<int> que;
level[s]=0;
que.push(s);
while(!que.empty()){
v=que.front();que.pop();
for(i=0;i<(int)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);
}
}
}
}
LL dfs(int v,int t,LL f){
if(v==t)
return f;
for(int &i=iter[v];i<(int)G[v].size();i++){
edge &e=G[v][i];
if(e.cap>0&&level[v]<level[e.to]){
LL 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;
}
LL max_flow(int s,int t){
LL flow=0;
for(;;){
bfs(s);
if(level[t]<0)
return flow;
memset(iter,0,sizeof(iter));
LL f;
while((f=dfs(s,t,INF))>0){
flow+=f;
}
}
}