AC日记——草地排水 codevs 1993
在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水。这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间。因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没的烦恼(不用担心,雨水会流向附近的一条小溪)。作为一名一流的技师,农夫约翰已经在每条排水沟的一端安上了控制器,这样他可以控制流入排水沟的水流量。
农夫约翰知道每一条排水沟每分钟可以流过的水量,和排水系统的准确布局(起点为水潭而终点为小溪的一张网)。需要注意的是,有些时候从一处到另一处不只有一条排水沟。
根据这些信息,计算从水潭排水到小溪的最大流量。对于给出的每条排水沟,雨水只能沿着一个方向流动,注意可能会出现雨水环形流动的情形。
第1行: 两个用空格分开的整数N (0 <= N <= 200) 和 M (2 <= M <= 200)。N是农夫John已经挖好的排水沟的数量,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
#include <cstdio>
#include <iostream> using namespace std; struct EdgeType {
int to,next,flow;
};
struct EdgeType edge[]; int if_z,n,m,cnt=,que[],ans,deep[],head[]; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} int flowing(int now,int flow)
{
if(flow==||now==m) return flow;
int oldflow=;
for(int i=head[now];i;i=edge[i].next)
{
if(edge[i].flow<=||deep[edge[i].to]!=deep[now]+) continue;
int pos=flowing(edge[i].to,min(flow,edge[i].flow));
flow-=pos;
oldflow+=pos;
edge[i].flow-=pos;
edge[i^].flow+=pos;
if(flow==) return oldflow;
}
return oldflow;
} int main()
{
in(n),in(m);int u,v,w;
for(int i=;i<=n;i++)
{
in(u),in(v),in(w);
edge[++cnt].to=v,edge[cnt].next=head[u],edge[cnt].flow=w,head[u]=cnt;
edge[++cnt].to=u,edge[cnt].next=head[v],edge[cnt].flow=,head[v]=cnt;
}
while()
{
for(int i=;i<=m;i++) deep[i]=-;
int h=,tail=;que[tail++]=,deep[]=;
bool if_break=false;
while(h<tail)
{
for(int i=head[que[h]];i;i=edge[i].next)
{
if(edge[i].flow&&deep[edge[i].to]<)
{
deep[edge[i].to]=deep[que[h]]+;
if(edge[i].to==m)
{
if_break=true;
break;
}
que[tail++]=edge[i].to;
}
}
if(if_break) break;
h++;
}
if(deep[m]<) break;
ans+=flowing(,0x7ffffff);
}
cout<<ans;
return ;
}
AC日记——草地排水 codevs 1993的更多相关文章
- AC日记——约瑟夫问题 codevs 1282
1282 约瑟夫问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description 有编号从1到N的N个小 ...
- AC日记——丑数 codevs 1246
1246 丑数 USACO 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 对于一给定的素 ...
- AC日记——砍树 codevs 1388
1388 砍树 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 伐木工人米尔科需要砍倒M米长的木 ...
- AC日记——元素查找 codevs 1230
1230 元素查找 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 给出n个正整数,然后有 ...
- AC日记——石子归并 codevs 1048
1048 石子归并 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 有n堆石子排成一列,每堆石子 ...
- AC日记——搞笑世界杯 codevs 1060(dp)
题目描述 Description 随着世界杯小组赛的结束,法国,阿根廷等世界强队都纷纷被淘汰,让人心痛不已. 于是有 人组织了一场搞笑世界杯,将这些被淘汰的强队重新组织起来和世界杯一同比赛.你和你的朋 ...
- AC日记——产生数 codevs 1009 (弗洛伊德)(组合数学)
1009 产生数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descriptio ...
- AC日记——平衡树练习 codevs 4244
4244 平衡树练习 思路: 有节操的人不用set也不用map: 代码: #include <cstdio> #include <cstring> #include <i ...
- AC日记——营业额统计 codevs 1296 (splay版)
营业额统计 思路: 每次,插入一个点: 然后找前驱后继: 来,上代码: #include <cmath> #include <cstdio> #include <iost ...
随机推荐
- vc生产垃圾清理
@echo off echo 清除所有obj pch idb pdb ncb opt plg res sbr ilk suo文件,请稍等...... pause del /f /s /q .\*.ob ...
- dhtmlTree简单实例以及基本参数设置
demo实例参考: <link rel="STYLESHEET" type="text/css" href="css/dhtmlXTree.c ...
- HTML防止重复提交
1 在你的表单页里HEAD区加入这段代码: <META HTTP-EQUIV="pragma" CONTENT="no-cache"> <ME ...
- oracle row_number的使用
create table studentInfo( id number(8) primary key, name varchar2(20) not null, ObjectName varcha ...
- verilog behaviral modeling -- procedural timing contronls
1.delay control : an expression specifies the time duration between initially encountering the state ...
- 解决php7.3 configure: error: off_t undefined
//解决该问题:php7.3 configure: error: off_t undefined; check your library configuration # 添加搜索路径到配置文件echo ...
- List<T> List<?> 区别用法
List<T>是泛型方法,List<?>是限制通配符 List<T>一般有两种用途:1.定义一个通用的泛型方法.伪代码: public interface Dao{ ...
- 本机机器ssh docker容器
https://blog.csdn.net/u010324465/article/details/77184506 1.在docker中安装openssh-server 2.sudo /etc/ini ...
- 修改JVM的参数、Jstat、Jstack、gclog
---恢复内容开始--- 1. jetty 修改JVM的参数 deploy/bin/env.sh 在上面的环境变量脚本中进行修改:如果分配给JVM的内存是4g 这个里面的JAVA_OPTS 的配置项就 ...
- Knockout v3.4.0 中文版教程-10-绑定-控制文本内容和外观-visible绑定
4.绑定 1. 控制文本内容和外观 1. visible绑定 目的 visible绑定可以根据你传入绑定的值控制关联的DOM元素显示或隐藏. 例子 <div data-bind="vi ...