# poj1273 Drainage Ditches（裸最大流）

Drainage Ditches

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Every time it rains on Farmer John‘s fields, a pond forms over Bessie‘s favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie‘s clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.

Input

The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that 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 will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.

Output

For each case, output a single integer, the maximum rate at which water may emptied from the pond.

Sample Input

``` 5 4 1 2 40 1 4 20 2 4 20 2 3 30 3 4 10
```

Sample Output

``` 50

```

1 #include<stdio.h>
2 #include<string.h>
3 #include<queue>
4 using namespace std;
5
6 int cap[205][205],pre[205];//cap 残量（残余网络），n 汇点
7 int n;
8 queue<int>p;
9
10 int _min(int a,int b)
11 {
12     return a<b?a:b;
13 }
14
15 void bfs()
16 {
17     int Maxflow = 0, i;
18     while(1)
19     {
20         pre[1]=1;
21         p.push(1);
22         int min=999999999;
23         memset(pre,0,sizeof(pre));
24         while(!p.empty())
25         {
26             int u=p.front();
27             p.pop();
28             for(i=1;i<=n;i++)
29             {
30                 if(pre[i]==0  && cap[u][i]>0)
31                 {
32                     pre[i]=u;
33                     p.push(i);
34                     min=_min(min,cap[u][i]);//找到此时遍历到的所有边的最短值，并不是增广路上的最小容量值
35                 }
36             }
37         }
38         if(pre[n]==0)  break;
39
40         for(int s=n; s!=1; s=pre[s]){
41             cap[pre[s]][s]-= min;
42             cap[s][pre[s]]+= min;
43         }
44         Maxflow += min;
45     }
46     printf("%d\n", Maxflow);
47 }
48
49 int main()
50 {
51     int m, a, b, c, i;
52     while(scanf("%d%d",&m,&n)!=EOF)
53     {
54         memset(cap,0,sizeof(cap));
55         for(i=0;i<m;i++)
56         {
57             scanf("%d%d%d",&a,&b,&c);
58             cap[a][b]+=c;
59         }
60         bfs();
61     }
62     return 0;
63 }

poj1273 Drainage Ditches（裸最大流）,布布扣,bubuko.com

## POJ-1273 Drainage Ditches 【最大流】

Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage

## POJ1273 Drainage Ditches 【最大流Dinic】

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56870   Accepted: 21863 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by

## POJ 1273 Drainage Ditches(网络流 最大流)

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 55893   Accepted: 21449 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by

## POJ 1273 Drainage Ditches (网络最大流)

http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 55235   Accepted: 21104 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means

## Drainage Ditches（最大流）

Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64044   Accepted: 24718 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by