博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1273 Drainage Ditches题解——S.B.S.
阅读量:5167 次
发布时间:2019-06-13

本文共 3665 字,大约阅读时间需要 12 分钟。

Drainage Ditches

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 67823   Accepted: 26209

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 41 2 401 4 202 4 202 3 303 4 10

Sample Output

50

Source

——————————我是分割线——————————————————————————————————————————————————
水题,模板题。
网络流,最大流。
增广路算法求解。
我竟然调了两个钟头......
正解是DINIC增广,但我直接BFS增广竟然也过了……
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #define maxn 210 9 using namespace std; 10 void find(); 11 void flow(); 12 void update(); 13 struct Edge 14 { 15 int c; 16 int f; 17 }edge[maxn][maxn]; 18 int n,m; 19 int s,t; 20 int residual[maxn][maxn]; 21 int que[maxn*maxn],head,tail; 22 int pre[maxn]; 23 bool vis[maxn]; 24 int max_flow,min_flow; 25 void find() 26 { 27 int i,cu; 28 memset(vis,false,sizeof(vis)); 29 memset(residual,0,sizeof(residual)); 30 memset(pre,0,sizeof(pre)); 31 head=0;que[head]=s;pre[s]=s;vis[s]=true;tail=1; 32 while(head
0) 40 { 41 residual[cu][i]=edge[cu][i].c-edge[cu][i].f; 42 pre[i]=cu;que[tail++]=i;vis[i]=true; 43 } 44 else if(edge[i][cu].f>0) 45 { 46 residual[cu][i]=edge[i][cu].f; 47 pre[i]=cu;que[tail++]=i;vis[i]=true; 48 } 49 } 50 } 51 head++; 52 } 53 } 54 void flow() 55 { 56 int i=t,j; 57 if(pre[i]==0) 58 { 59 min_flow=0;return; 60 } 61 j=0x7fffffff; 62 while(i!=s) 63 { 64 if(residual[pre[i]][i]
0) 76 edge[pre[i]][i].f+=min_flow; 77 else if(edge[i][pre[i]].f>0) 78 edge[pre[i]][i].f+=min_flow; 79 i=pre[i]; 80 } 81 } 82 void solve() 83 { 84 s=1;t=n; 85 max_flow=0; 86 while(true) 87 { 88 find();flow(); 89 max_flow+=min_flow; 90 if(min_flow>0) update(); 91 else return; 92 } 93 } 94 int main() 95 { 96 std::ios::sync_with_stdio(false); 97 int i,u,v,c; 98 while(scanf("%d %d",&m,&n)!=EOF) 99 {100 memset(edge,0,sizeof(edge));101 for(i=0;i
View Code

 

转载于:https://www.cnblogs.com/AwesomeOrion/p/5536745.html

你可能感兴趣的文章
关于JSplitPane在setDividerLocation(int)之后,折叠时大小变化的问题
查看>>
Ruby and Rails
查看>>
word页面线条快速去除点击清除所有格式就可以了
查看>>
WCF 服务的集合管理器的设计
查看>>
《大型网站技术架构》笔记
查看>>
力荐一款免费刷百度下拉框,刷百度相关,刷百度排名的小软件
查看>>
架构之路之spring+redis的集成
查看>>
适合最新版docker自定义启动配置
查看>>
使用nodejs 访问mongodb
查看>>
Android-锁屏功能
查看>>
linux-Centos7安装python3并与python2共存
查看>>
网络协议 11 - Socket 编程(下):眼见为实耳听为虚
查看>>
about control %CPU
查看>>
你这是virus吧?
查看>>
嵌入式系统设计与实践
查看>>
[转]IIS6 伪静态 IIS文件类型映射配置方法 【图解】
查看>>
Fastcgi、CGI 是什么
查看>>
Makefile中变量定义中末尾不能有空格
查看>>
JBoss平台下JTA与JMS实验软件架构8
查看>>
YuiDoc
查看>>