[网络流]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 ...
随机推荐
- vue组件知识点
1.组件的定义 const component = { props: { //外部父组件约束子组件的 里面不要修改 可以通过触发事件来修改 active: Boolean, propOne: Stri ...
- 接收Android数据 递归显示表格数据
<html> <head> <title>展示</title> <script type="text/javascript" ...
- 大型运输行业实战_day15_1_全文检索之Lucene
1.引入 全文检索简介: 非结构化数据又一种叫法叫全文数据.从全文数据(文本)中进行检索就叫全文检索. 2.数据库搜索的弊端 案例 : select * from product whe ...
- Light Probe
[Light Probe] Light Probes provide a way to capture and use information about light that is passing ...
- Photoshop Keynote
[Photoshop Keynote] 1.Tab:隐藏.显示所有面板. 2.Sihft+Tab:隐藏.显示右侧面板. 3.F:全屏切换. 4.选择并遮住: 参考:http://www.51shipi ...
- 在centos xmanager工具环境下启动 xwindow
# 安装epel源 [root@linuxidc ~]# yum install -y epel-release # 安装lightdm和Xfce 1.安装 lightdm sudo yum inst ...
- JMeter学习(二十四)HTTP属性管理器HTTP Cookie Manager、HTTP Request Defaults(转载)
转载自 http://www.cnblogs.com/yangxia-test Test Plan的配置元件中有一些和HTTP属性相关的元件:HTTP Cache Manager.HTTP Autho ...
- Android学习路-UI控件
- 在window下搭建Vue.Js开发环境(转)
nodejs官网http://nodejs.cn/下载安装包,无特殊要求可本地傻瓜式安装,这里选择2017-5-2发布的 v6.10.3 cmd命令行: node -v //显示node版本 v6.1 ...
- docker save 批量导出脚本
[root@vultr home]# cat docker_sove.sh docker images > images.txtawk '{print $1}' images.txt > ...