题意:
现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的点和所能流过的最大流量,
求从源点到汇点能流过的最大流量。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 205
#define INF 1000001
int cap[maxn][maxn];
int flow[maxn][maxn];
int a[maxn],p[maxn];
int main()
{
int n,m;
while(~scanf("%d %d",&m,&n))
{
memset(cap,0,sizeof(cap));
memset(flow,0,sizeof(flow));
int x,y,c;
for(int i=0; i<m; i++)
{
scanf("%d %d %d",&x,&y,&c);
cap[x][y]+=c;
}
int s=1,t=n;
queue<int>q;
int f=0;
for(;;)
{
memset(a,0,sizeof(a));
a[s]=INF;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int v = 1; v <= n; v++)
if(!a[v] && cap[u][v] > flow[u][v])
{
p[v] = u; q.push(v);
a[v] = min(a[u], cap[u][v]-flow[u][v]);
}
}
if(a[t]==0)
break;
for(int u=t;u!=s;u=p[u])
{
flow[p[u]][u]+=a[t];
flow[u][p[u]]-=a[t];
}
f+=a[t];
}
printf("%d\n",f);
}
return 0;
}