#include #include #include #include #include #include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f #define mod 10000 typedef long long ll; using namespace std; const int N=505; const int M=100005; int n,m,k,ans,t; int pre[N]; struct man { int c,f; }w[N][N]; bool bfs() { queueq; q.push(1); memset(pre,0,sizeof(pre)); pre[1]=1; while(!q.empty()){ int u=q.front();q.pop(); for(int i=1;i<=t;i++){ if( !pre[i] && w[u][i].c>w[u][i].f){ pre[i]=pre[u]+1; q.push(i); } } } return pre[t]!=0; } int dfs(int u,int sum) { if(u==t||sum==0)return sum; int tmp=sum,minn; for(int i=1;i<=t;i++){ if(pre[i]==pre[u]+1&&w[u][i].c>w[u][i].f){ minn=dfs(i,min(tmp,w[u][i].c-w[u][i].f)); w[u][i].f+=minn; w[i][u].f -=minn; tmp-=minn; } } return sum-tmp; } void Dinic() { ans=0; while(bfs())ans+=dfs(1,inf); cout<