Recommend a learning network into the door of the data http://acm.pku.edu.cn/summerschool/gw_netflow.pdf
This is titled Network water Problem, also is a PDF of the network flow of a problem, pay attention to the heavy edge.
#include <iostream>#include<cstdio>#include<cstring>#include<queue>#include<cstdlib>using namespacestd;intn,m;Long Longg[ -][ -];intvis[ -];intpre[ -];Long Longaugmented () {memset (Vis,0,sizeof(VIS)); memset (PRE,0,sizeof(pre)); Queue<int>que; while(!Que.empty ()) {Que.pop (); } Que.push (1); vis[1]=1; BOOLflag=false; while(!Que.empty ()) { intD=Que.front (); Que.pop (); for(intI=1; i<=m;i++){ if(g[d][i]>0&&!Vis[i]) {Pre[i]=D; Vis[i]=1; if(i==m) {Flag=true; while(!Que.empty ()) {Que.pop (); } Break; } Else{Que.push (i); } } } } if(flag) {Long Longmin=999999999; intD=m; while(Pre[d]) {Min=min (min,g[pre[d]][d]); D=Pre[d]; } d=m; while(Pre[d]) {G[pre[d]][d]-=Min; G[D][PRE[D]]+=Min; D=Pre[d]; } returnMin; } return 0;}intMain () { while(~SCANF ("%d%d",&n,&m)) {memset (g,0,sizeof(g)); for(intI=0; i<n;i++){ intu,v; Long LongW; scanf ("%d%d%lld",&u,&v,&W); G[U][V]+=W; } Long Longflow; Long Longmaxflow=0; while(flow=augmented ()) {Maxflow+=flow; } printf ("%lld\n", Maxflow); } return 0;}
POJ 1273 Network Flow first question (PDF link)