Topic Links: http://acm.hdu.edu.cn/showproblem.php?pid=3549
Thinking Analysis: The problem is bare maximum network flow problem, the data is not large, using the EDMONDSKARP algorithm can be solved; it is important to note that there are up to 15 points for this problem, and the number of edges is up to 1000, so there are heavy edges in the graph, and multiple heavy edges need to be combined as one edge;
The code is as follows:
#include <queue>#include<vector>#include<cstdio>#include<climits>#include<cstring>#include<iostream>using namespacestd;Const intMax_n = -;intCap[max_n][max_n], flow[max_n][max_n];intA[max_n], P[max_n];inlineintMin (intAintb) {returnA < b?a:b;}intEdmondskarp (intver_num) {Queue<int>Q; intMax_flow =0; memset (Flow,0,sizeof(flow)); for (;;) {memset (A,0,sizeof(a)); a[1] =Int_max; Q.push (1); while(!Q.empty ()) { intU =Q.front (); Q.pop (); for(intv =1; V <= ver_num; ++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[ver_num] = =0) Break; for(intu = ver_num; U! =1; U =P[u]) {Flow[p[u]][u]+=A[ver_num]; Flow[u][p[u]]-=A[ver_num]; } Max_flow+=A[ver_num]; } returnMax_flow;}intMain () {intCase_times, case_id =0; intRoad_num, Ver_num; scanf ("%d", &case_times); while(case_times--) { intver_1, ver_2, CAPA; scanf ("%d%d", &ver_num, &road_num); memset (Cap,0,sizeof(CAP)); for(inti =0; i < Road_num; ++i) {scanf (" %d%d%d", &ver_1, &ver_2, &CAPA); Cap[ver_1][ver_2]+=Capa; } intAns =Edmondskarp (Ver_num); printf ("Case %d:%d\n", ++case_id, ans); } return 0;}
Hdoj 3549 Flow problem (maximum network flow)