[网络流]Drainage Ditches(草地排水)
Drainage Ditches(草地排水)
题目描述
在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水。这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间。因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没的烦恼(不用担心,雨水会流向附近的一条小溪)。作为一名一流的技师,农夫约翰已经在每条排水沟的一端安上了控制器,这样他可以控制流入排水沟的水流量。
农夫约翰知道每一条排水沟每分钟可以流过的水量,和排水系统的准确布局(起点为水潭而终点为小溪的一张网)。需要注意的是,有些时候从一处到另一处不只有一条排水沟。
根据这些信息,计算从水潭排水到小溪的最大流量。对于给出的每条排水沟,雨水只能沿着一个方向流动,注意可能会出现雨水环形流动的情形。。
输入
| 第1行: | 两个用空格分开的整数N (0 <= N <= 200) 和 M (2 <= M <= 200)。N是农夫约翰已经挖好的排水沟的数量,M是排水沟交叉点的数量。交点1是水潭,交点M是小溪。 |
| 第二行到第N+1行: | 每行有三个整数,Si, Ei, 和 Ci。Si 和 Ei (1 <= Si, Ei <= M) 指明排水沟两端的交点,雨水从Si 流向Ei。Ci (0 <= Ci <= 10,000,000)是这条排水沟的最大容量。 |
输出
输出一个整数,即排水的最大流量。
样例输入
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
样例输出
50 就是一道模板题QAQQ
本蒟蒻花了20分钟调结果发现"%d%d%d"写成"%d%d&d"
美滋滋~
代码:
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue> const int Maxv = , INF = 0x6ffffff;
int Dep[Maxv], W[Maxv], V[Maxv], Head[Maxv], Next[Maxv], cnt, n, s = , t; void Add(int u, int v, int w){
cnt++;
Next[cnt] = Head[u];
V[cnt] = v;
W[cnt] = w;
Head[u] = cnt;
} void Add_Edge(int u, int v, int w){
Add(u, v, w);
Add(v, u, );
} bool BFS(){
std::queue<int> Q;
while (!Q.empty()) {
Q.pop();
}
memset(Dep, , sizeof(Dep));
Dep[s] = ;
Q.push(s);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (int i = Head[u]; ~i; i = Next[i]) {
if (W[i] > && Dep[V[i]] == ) {
Dep[V[i]] = Dep[u] + ;
Q.push(V[i]);
}
}
}
if (Dep[t] > ) {
return true;
}
return false;
} int DFS(int u, int dist){
if (u == t) {
return dist;
}
for (int i = Head[u]; ~i; i = Next[i]) {
if (Dep[V[i]] == Dep[u] + && W[i] != ) {
int di = DFS(V[i], std::min(dist, W[i]));
if (di > ) {
W[i] -= di;
W[i ^ ] += di;
return di;
}
}
}
return ;
} int Dinic(){
int Ans = ;
while (BFS()) {
while (int d = DFS(s, INF)) {
Ans += d;
}
}
return Ans;
} int main(){
int x, y, val;
scanf("%d%d", &n, &t);
memset(Head, - ,sizeof(Head));
memset(Next, - ,sizeof(Next));
for (int i = ; i <= n; i++) {
scanf("%d%d%d", &x, &y, &val);
Add_Edge(x, y, val);
}
printf("%d", Dinic());
return ;
}
[网络流]Drainage Ditches(草地排水)的更多相关文章
- 【USACO】草地排水
Drainage Ditches 草地排水 usaco 4.2.1描述在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一 ...
- USACO 4.2 Drainage Ditches(网络流模板题)
Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- 【网络流】POJ1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 78671 Accepted: 3068 ...
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU-1532 Drainage Ditches,人生第一道网络流!
Drainage Ditches 自己拉的专题里面没有这题,网上找博客学习网络流的时候看到闯亮学长的博客然后看到这个网络流入门题!随手一敲WA了几发看讨论区才发现坑点! 本题采用的是Edmonds-K ...
- - > 网络流(草地排水)
网络流(Dinic(模板)) Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- POJ 1273 Drainage Ditches (网络流Dinic模板)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
随机推荐
- Rendering with Replaced Shaders
[Rendering with Replaced Shaders] 1.RenderType tag RenderType tag categorizes shaders into several p ...
- 关于Android file.createNewFile() 失败的问题
[关于Android file.createNewFile() 失败的问题] 需要注意的是:要先对设计的文件路径创建文件夹 , 然后在对文件进行创建. 参考:http://blog.csdn.net/ ...
- xnconvert 图片转换工具
xnconvert是一款简单高效的图片转换工具.xnconvert能够批量地进行图片格式转换,并具有一定的图片处理功能,可以增加水印.特效,支持放大缩小.旋转等. xnconvert功能介绍: 你可以 ...
- Spring之jdbcTemplate实现orm
public List<AppUser> getAppUser(AppUser appUser) { String sql = "select * from appuser a ...
- c++ 面试题(汇总)
1,extern 关键字作用: http://www.cnblogs.com/lzjsky/archive/2010/11/24/1886686.html 2,static 关键字作用: https: ...
- Python memoryview() 函数
Python memoryview() 函数 Python 内置函数 描述 memoryview() 函数返回给定参数的内存查看对象(Momory view). 所谓内存查看对象,是指对支持缓冲区协 ...
- Zabbix 3.0编译安装
环境准备Centos 6.X 数据库准备默认centos yum源中mysql包的版本号为5.1,为了能使zabbix 3.0能达到最好的性能效果,安装最新版的mysql数据库. yum list i ...
- 如何在比较1.5 len的次数下,找到整型数组最大最小值
2016-11-11 #include <iostream> #include<stdlib.h> #include<stdio.h> using namespac ...
- 802.1X技术介绍
1.802.1X IEEE802 LAN/WAN委员会为解决无线局域网网络安全问题,提出了802.1X协议.后来,802.1X协议作为局域网端口的一个普通接入控制机制在以太网中被广泛应用,主要解决以太 ...
- f5会话保持
B/S架构的建议选择 inset cookie :c/s架构的 建议选择 sorce ip 1. Introduction to session persistence profiles Using ...