#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<queue>using namespacestd;intdp[ -][ -],pre[ -];Const inttmin=999999999;intMaxflow;voidEK (intStartintEndintN) { while(1) {Queue<int>P; Q.push (1);//source point is 1, incoming team intminflow=tmin; memset (PRE,0,sizeof(pre));//Initializes an array of augmented paths, with the vertices in the title starting from 1 while(!q.empty ()) {//BFS find augmented Road intu=Q.front (); Q.pop (); for(intI=1; i<=n;i++){ if(dp[u][i]>0&&!pre[i]) {//Pre[i] In addition to recording the current vertex of the father, also record the current vertex has not been visitedpre[i]=u; Q.push (i); } } } if(pre[end]==0)//the vertex of the father is empty, indicating that the augmented path can not be found, it is easy to understand it. Break; for(intI=end;i!=start;i=pre[i]) {//finding the minimum residual amount in the augmented pathminflow=min (dp[pre[i]][i],minflow); } for(intI=end;i!=start;i=pre[i]) {//increased flow of positive and negative arcs in the wide roaddp[pre[i]][i]-=Minflow; Dp[i][pre[i]]+=Minflow; } Maxflow+=Minflow; }}intMain () {intCount=0; intn,m; intT; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); Memset (DP,0,sizeof(DP)); memset (PRE,0,sizeof(pre)); Count++; intu,v,w; for(intI=1; i<=m;i++) {scanf ("%d%d%d",&u,&v,&W); DP[U][V]+=W; } Maxflow=0; EK (1, N,n); printf ("Case %d:%d\n", Count,maxflow); } return 0;}
EK algorithm template