hdu1532 Drainage Ditches
来源:互联网 发布:金拱门域名价格 编辑:程序博客网 时间:2024/06/07 21:05
传送门
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.
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.
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.
For each case, output a single integer, the maximum rate at which water may emptied from the pond.
5 41 2 401 4 202 4 202 3 303 4 10
50题意:
给出n个河流,m个点,以及每个河流的流量,求从1到m点的最大流量
裸的最大流算法,套用模板即可
#include<stdio.h>#include<iostream>#include<set>#include<queue>#include<algorithm>#include<math.h>#include<string.h>#include<string>#include<vector>using namespace std;const int inf = 0x3f3f3f3f ;const int maxn = 1e5+5 ;struct edge{ int to , cap , rev ;};vector<edge> G[maxn];bool used[maxn];void add_edge(int from , int to , int cap){ edge e1 , e2 ; e1.to = to; e1.cap = cap ; e1.rev = G[to].size(); G[from].push_back(e1); e2.to = from; e2.cap = 0 ; e2.rev = G[from].size() - 1; G[to].push_back(e2);}int dfs(int v , int t , int f){ if(v == t) return f ; used[v] = true; for(int i = 0 ; i <G[v].size() ; i ++){ edge &e = G[v][i] ; if(!used[e.to] && e.cap > 0){ int d = dfs(e.to , t , min(f , e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0;}int max_flow(int s , int t){ int flow = 0 ; for( ; ; ){ memset(used , false , sizeof(used)); int f = dfs(s , t , inf); if(f == 0 ) return flow ; flow += f ; }}int main(){ int n , m ; while(~scanf("%d%d",&n,&m)){ for(int i = 0 ; i <= m ; i++) G[i].clear(); for(int i = 0 ; i < n ; i ++){ int u , v , cap ; scanf("%d%d%d",&u , &v , &cap); add_edge(u , v , cap); } cout<<max_flow(1 , m)<<endl; } return 0;}
阅读全文
0 0
- HDU1532--Drainage Ditches
- hdu1532 Drainage Ditches
- hdu1532 Drainage Ditches (Dinic)
- hdu1532 Drainage Ditches
- HDU1532 Drainage Ditches
- hdu1532 Drainage Ditches
- HDU1532----Drainage Ditches
- Drainage Ditches [HDU1532]
- hdu1532-Drainage Ditches
- HDU1532 Drainage Ditches (maxflow_Dinic)
- POJ1273&&HDU1532-Drainage Ditches
- hdu1532 Drainage Ditches
- HDU1532-Drainage Ditches
- HDU1532 Drainage Ditches 最大流
- HDU1532 Drainage Ditches Dinic算法
- HDU1532 Drainage Ditches 【最大流】
- HDU1532 - Drainage Ditches(网络流)
- HDU1532 Drainage Ditches(网络流模板)
- SharedPreferences保存list集合
- 有关密码本小项目的一些知识点总结(二)
- 【数据库系统概念】第5章 高级SQL 知识总结
- 在已有win7系统的基础上重装win10系统
- 关注民生民情——华北水利水电大学“情艺”国情社情调查
- hdu1532 Drainage Ditches
- 【EXTJS入门】extjs 和 sencha cmd的下载
- 据说题目很水
- jQuery判断checkbox是否选中的3种方法
- Spring RestTemplate SSL请求
- Hiveserver2的使用
- iframe上左右布局
- 线性插值法
- 关注民生民情——华北水利水电大学“情艺”国情社情调查