可耻的把模板扔上去就过了
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#define maxn 220
#define INF 0x7fffffff
using namespace std;
int cap[201][201],flow[201][201],a[201];
//cap[][]表示最大容量,flow[][]表示当前流量
int s,t,n,m;
void ek()
{
queue<int> q;
int p[201],u,v;
memset(flow,0,sizeof(flow));
int f=0;
while(1)
{
memset(a,0,sizeof(a));
memset(p,0,sizeof(p));
a[s]=INF;
q.push(s);
while(!q.empty())
{
u=q.front();
q.pop();
for(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(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);
}
int main()
{
freopen("ditch.in","r",stdin);
freopen("ditch.out","w",stdout);
while(scanf("%d %d",&n,&m)!=EOF)
{
int i,si,ei,ci;
memset(cap,0,sizeof(cap));
for(i=0;i<n;i++)
{
scanf("%d %d %d",&si,&ei,&ci);
cap[si][ei]+=ci;
}
s=1;
t=m;
ek();
}
return 0;
}