poj1273--Drainage Ditches（最大流）

Drainage Ditches

 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56084 Accepted: 21547

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`
` `
`直接建图，模板`
` `
```#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define maxn 500
#define INF 0x3f3f3f3f
struct edge{
int v , w ;
int next ;
} p[maxn];
int head[maxn] , cnt , pre[maxn] , vis[maxn] ;
queue <int> q ;
{
p[cnt].v = v ; p[cnt].w = w ;
p[cnt].v = u ; p[cnt].w = 0 ;
}
int bfs(int s,int t)
{
int u , v , min1 = INF , i ;
memset(vis,0,sizeof(vis));
vis[s] = 1 ;
while( !q.empty() )
q.pop() ;
q.push(s) ;
while( !q.empty() )
{
u = q.front();
q.pop() ;
for(i = head[u] ; i != -1 ; i = p[i].next)
{
v = p[i].v ;
if( !vis[v] && p[i].w )
{
vis[v] = 1 ;
min1 = min(min1,p[i].w) ;
pre[v] = i ;
q.push(v) ;
}
}
}
if( vis[t] )
return min1 ;
return -1 ;
}
int main()
{
int n , m , u , v , w , max_flow , i;
while(scanf("%d %d", &m, &n)!=EOF)
{
cnt = 0 ;max_flow = 0 ;
while(m--)
{
scanf("%d %d %d", &u, &v, &w);
}
memset(pre,-1,sizeof(pre)) ;
while(1)
{
int k = bfs(1,n);
if(k == -1)
break;
max_flow += k ;
for(i = pre[n] ; i != -1 ; i = pre[ p[i^1].v ])
{
p[i].w -= k ;
p[i^1].w += k ;
}
}
printf("%d\n", max_flow);
}
return 0;
}
```

poj1273--Drainage Ditches（最大流）

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 Joh

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 【最大流】

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

hdu 1532 Drainage Ditches(最大流）

Drainage Ditches 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 drai

poj 1273 Drainage Ditches (最大流入门）

1 /****************************************************************** 2 题目: Drainage Ditches(POJ 1273) 3 链接: http://poj.org/problem?id=1273 4 题意: 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条 5 水渠,给出这n条水渠所连接的池塘和所能流过的水量,求水 6 渠中所能流过的水的最大容量.水流是单向的. 7 算法: 最大流之增广路(入门)