#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
int n,m;
int cap[210][210];
int flow[210][210];
int a[210];
const int INF=1000000000;
int EK(int s,int t)
{
queue<int> q;
memset(flow,0,sizeof(flow));
int p[210];
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<=m;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];
}
return f;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(cap,0,sizeof(cap));
for(int i=0;i<n;i++)
{
int s,e,c;
scanf("%d%d%d",&s,&e,&c);
/*if((cap[s][e]==0)||(cap[s][e]!=0&&c>cap[s][e]))
{
cap[s][e]=c;
//cap[e][s]=0;
}*/
cap[s][e]+=c;
}
printf("%d\n",EK(1,m));
}
return 0;
}
POJ1273 Drainage Ditches (最大流+入门题)
最新推荐文章于 2024-08-29 16:23:28 发布