#include<cstdio> #include<iostream> #include<cstring> #include<queue> #define INF 9999999 #define M 330 using namespace std; int maxflow,pre[M],map[M][M],n,m; void Flow(int start,int end) { while(1) { queue<int> p; int minflow=INF; p.push(1); memset(pre,0,sizeof(pre)); while(!p.empty()) { int u=p.front(); p.pop(); if(u==end)break; for(int i=1;i<=m;i++) if(map[u][i]&&!pre[i]) { pre[i]=u; p.push(i); } } if(pre[end]==0)break;//找不到增广路径 for(int i=end;i!=start;i=pre[i]) minflow=min(minflow,map[pre[i]][i]); for(int i=end;i!=start;i=pre[i]) { map[pre[i]][i]-=minflow; map[i][pre[i]]+=minflow; } maxflow+=minflow; } } int main() { while(~scanf("%d%d",&n,&m)) { int a,b,f; memset(map,0,sizeof(map)); for(int i=1;i<=n;i++) { scanf("%d%d%d",&a,&b,&f); map[a][b]+=f; } maxflow=0; Flow(1,m); printf("%d ",maxflow); } return 0; }