#include <iostream>
#include <cstdio>
using namespace std;
const int oo = 1e9+5;
const int mm = 111111;
const int mn = 1000;
int node, src, dest, edge;
int ver[mm], flow[mm], next[mm];
int head[mn], work[mn], dis[mn], q[mn];
void Init(int _node, int _src, int _dest)
{
node = _node, src = _src, dest = _dest;
for(int i=0; i<node; i++)
head[i] = -1;
edge = 0;
}
void addedge(int u, int v, int c)
{
ver[edge]=v,flow[edge]=c,next[edge]=head[u],head[u]=edge++;
ver[edge]=u,flow[edge]=0,next[edge]=head[v],head[v]=edge++;
}
bool Dinic_bfs()
{
int i, u, v, l, r = 0;
for(i=0; i<node; i++)
dis[i] = -1;
dis[q[r++]=src] = 0;
for(l=0; l<r; l++)
for(i=head[u=q[l]]; i>=0; i=next[i])
if(flow[i] && dis[v=ver[i]]<0)
{
dis[q[r++]=v] = dis[u] + 1;
if(v == dest)
return 1;
}
return 0;
}
int Dinic_dfs(int u, int exp)
{
if(u == dest)
return exp;
for(int &i=work[u],v,tmp; i>=0; i=next[i])
{
if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0)
{
flow[i] -= tmp;
flow[i^1] += tmp;
return tmp;
}
}
return 0;
}
int Dinic_flow()
{
int i, ret=0, data;
while(Dinic_bfs())
{
for(i=0; i<node; i++)
work[i] = head[i];
while(data = Dinic_dfs(src, oo))
ret += data;
}
return ret;
}