Detailed Explanation: http://blog.csdn.net/smartxxyx/article/details/9293665
Next, I'll put my first maximum flow problem:
hdu3549
1#include <stdio.h>2#include <algorithm>3#include <stdlib.h>4#include <iostream>5#include <string.h>6#include <math.h>7#include <vector>8#include <map>9#include <queue>Ten structpp One { A intx; - intcap; - intPre; the }; - Const intn=1e8; - BOOLused[ -]; - using namespacestd; +vector<pp>gg[ -]; - voidAddint from,intTo,intVV) + {pp ss; ASs.cap=vv;ss.x=to;ss.pre=gg[to].size (); atgg[ from].push_back (ss); -ss.cap=0; ss.x= from; ss.pre=gg[ from].size ()-1; - Gg[to].push_back (ss); - } - intDfsintXintYintCO) - { in if(x==y) - { to returnCo; + } -used[x]=true; the inti,j; * for(i=0; I<gg[x].size (); i++) ${intcc;Panax NotoginsengPP &ll=Gg[x][i]; - if(!used[ll.x]&&ll.cap>0) the { +Cc=Dfs (Ll.x,y,min (co,ll.cap)); A if(cc>0) the { +ll.cap-=cc; -gg[ll.x][ll.pre].cap+=cc; $ returncc; $ } - } - } the return 0; - }Wuyi intMax_flow (intXintt) the { - intflow=0; Wu while(1) -{memset (used,0,sizeof(used)); About intkk=DFS (x,t,n); $ if(kk==0) - { - returnflow; - } A Elseflow+=KK; + } the - } $ intMainvoid) the { the inti,j,k,p,q; thescanf"%d",&k); the - for(i=1; i<=k;i++) in{ for(j=0;j< -; j + +) the gg[j].clear (); thescanf"%d%d",&p,&q); About intXintYintn,m; the for(j=0; j<q;j++) the { thescanf" %d%d%d",&x,&y,&n); + Add (x,y,n); - } the intM=max_flow (1, p);Bayiprintf"Case %d:%d\n", i,m); the } the return 0; -}
Ford-fulkerson template for maximum flow problem