HDU 1532 Drainage ditches (maximum network flow)

Source: Internet
Author: User

Drainage Ditchestime limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other) total submission (s): 5 Accepted Submission (s): 3font:times New Roman | Verdana | Georgiafont Size:←→problem descriptionevery time it rains on Farmer John's fields, a pond forms over Bessie ' s favorite C Lover Patch. This means, the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John had built a set of drainage ditches so that Bessie ' s clover Patch was never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John have also installed regulators at the beginning of all ditch, so he can control at what Rate water flows to that ditch.
Farmer John knows not only what many gallons of water each ditch can transport per minute but also the exact layout of the Ditches, which feed out of the the pond and to each other and stream in a potentially complex network.
Given All this information, determine the maximum in which water can be transported off of the pond and into the stre Am. For any given ditch, water flows on only one direction, but there might be a-a-to-water can flow in a CIRCLE.&NBSP;INP Utthe input includes several cases. For each case, the first line contains the space-separated integers, n (0 <= n <=) and M (2 <= M <= 200). N is the number of ditches this Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection Point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and ei (1 <= Si, ei <= M) Designate the intersections between which this ditch flows. Water would flow through this ditch from Si to Ei. CI (0 <= ci <= 10,000,000) is the maximum rate at which water would flow through the ditch. Outputfor each case, output a single integer, the maximum rate in which water may emptied from the POND.&NBsp Sample Input
5 41 2 401 4 202 4 202 3 303 4 10
Sample Output
50
#include <iostream>#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespacestd;Const intinf=0x7fffffff;intvis[202],pre[202],mp[202][202];inti,n,m,sum;Long Longans;intBFs () {intFindpath=0; Queue<int>Q; memset (Vis,0,sizeof(VIS)); memset (PRE,0,sizeof(pre)); pre[1]=0; vis[1]=1; Q.push (1);  while(!Q.empty ()) {        intu=Q.front ();        Q.pop ();  for(intI=1; i<=n;i++)            if(mp[u][i]>0&&!Vis[i]) {Vis[i]=1; Pre[i]=u;            Q.push (i); if(i==n) {findpath=1; Break;} }    }    if(!findpath)return 0; intmaxflow=inf; intv=N;  while(pre[v]>0) {Maxflow=min (maxflow,mp[pre[v]][v]); V=Pre[v]; } v=N;  while(pre[v]>0) {Mp[v][pre[v]]+=Maxflow; MP[PRE[V]][V]-=Maxflow; V=Pre[v]; }    returnMaxflow;}intMain () { while(~SCANF ("%d%d",&m,&N) {memset (MP,0,sizeof(MP));  for(i=1; i<=m;i++)        {            intx, Y, Z scanf ("%d%d%d",&x,&y,&z); Mp[x][y]+=z;//looking for a long time error, finally found that there may be a lot of repetition, to accumulate} ans=0;  while(Sum=bfs ()) ans+=sum; printf ("%d\n", ans); }    return 0;}

HDU 1532 Drainage ditches (maximum network flow)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.