【CodeVS 1993】草地排水 isap模板题
开始网络流的学习,更新一下isap的模板
#include<cstdio>
#include<cstring>
#include<algorithm>
#define read(x) x=getint()
using namespace std;
const int N = 403;
int getint() {
int k = 0, fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - '0';
return k * fh;
}
int cap[N], d[N], cur[N], point[N], nxt[N], gap[N], p[N], to[N], from[N], cnt = 1;
void ins(int x, int y, int z) {
nxt[++cnt] = point[x]; to[cnt] = y; cap[cnt] = z; from[cnt] = x; point[x] = cnt;
}
int isap(int s, int t, int n) {
int flow = 0, i, u, f = 0x7fffffff;
memset(gap, 0, sizeof(gap)); memset(d, 0, sizeof(d));
for(int i = 0; i <= n; ++i)
cur[i] = point[i];
u = s; gap[0] = n;
while (d[s] < n) {
for(i = cur[u]; i; i = nxt[i]) if (cap[i] && d[u] == d[to[i]] + 1) break;
if (i) {
cur[u] = i; p[to[i]] = i; u = to[i];
if (u == t) {
for(f = 0x7fffffff; u != s; u = from[p[u]]) f = min(f, cap[p[u]]);
for(u = t; u != s; u = from[p[u]]) cap[p[u]] -= f, cap[p[u] ^ 1] += f;
flow += f;
}
} else {
if (!(--gap[d[u]])) break;
d[u] = n;
cur[u] = point[u];
for(i = cur[u]; i; i = nxt[i])
if (cap[i] && d[u] > d[to[i]] + 1)
d[u] = d[to[i]] + 1;
++gap[d[u]]; if (u != s) u = from[p[u]];
}
}
return flow;
}
int main() {
memset(point, 0, sizeof(point));
int u, v, e, n, m;
read(m); read(n);
for(int i = 1; i <= m; ++i) {
read(u); read(v); read(e);
ins(u, v, e);
ins(v, u, 0);
}
printf("%d\n", isap(1, n, n));
return 0;
}
233
【CodeVS 1993】草地排水 isap模板题的更多相关文章
- Codevs 1993 草地排水
1993 草地排水 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地 ...
- codevs 1993草地排水
1993 草地排水
- 模板题 codevs 1993 草地排水 想学习的请看链接
不能再水的题了. Dinic算法,比EK更快. 想要学习请看链接 https://comzyh.com/blog/archives/568/ 并附上我的模板(其实和comzyh大神的一样) #in ...
- codevs 1993 草地排水 USACO
/*Dinic*/ #include<iostream> #include<cstdio> #include<cstring> #include<queue& ...
- HDU 4280:Island Transport(ISAP模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...
- CODEVS——T 1993 草地排水 USACO
http://codevs.cn/problem/1993/ 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 De ...
- 【CodeVS】1993草地排水
题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水 ...
- 【最大流】【CODEVS】1993 草地排水
[算法]网络流-最大流(dinic) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html #include<cstdio> #includ ...
- AC日记——热浪 codevs 1557 (最短路模板题)
1557 热浪 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...
随机推荐
- 阿里云 CentOS6.5 ssh连接慢的解决方案
我租了一台阿里云深圳的服务器,用的是CentOS6.5的系统,最近要在服务器上小改点代码,但是不管用private shell 还是securecrt工具连接,连上去后,都特别慢,经常敲一段代码要过个 ...
- js获取鼠标位置的各种方法
在一些DOM操作中我们经常会跟元素的位置打交道,鼠标交互式一个经常用到的方面,令人失望的是不同的浏览器下会有不同的结果甚至是有的浏览器下没结果,这篇文章就上鼠标点击位置坐标获取做一些简单的总结,没特殊 ...
- 常用的SQL 语句
一.简单查询语句 1. 查看表结构 SQL>DESC emp; 2. 查询所有列 SQL>SELECT * FROM emp; 3. 查询指定列 SQL>SELECT empmo, ...
- ubuntu在命令行新建用户后无法进入桌面的原因
在命名行模式下 用useradd新建一个用户后 在图形界面输入密码无法登陆 这是因为未对新建的用户进行任何配置 用adduser命令新建用户即可进入桌面 下面说一下useradd 和 adduser的 ...
- Git版本恢复命令reset(转载)
本博文转载自:http://www.tech126.com/git-reset/: 如果看不懂的话,请在git下练习,如果练习后任然有不懂的,可以留言也可以发送邮件到luoquantao@126.co ...
- Oracle Delete inner的方式,级联删除子表的数据方式。
例子1: from table2 b where a.id=b.id) 例子2: rebatepolicy表是主表,rebatepolicyitems是从表,从表有主表的主键,现在对于主表一些条件的数 ...
- js获取样式的兼容写法
var currentStyle = function(element){ return element.currentStyle || document.defaultView.getCompute ...
- JavaScript中清空数组的三种方式
方式1,splice ? 1 2 3 var ary = [1,2,3,4]; ary.splice(0,ary.length); console.log(ary); // 输出 [],空数组,即被清 ...
- Swagger 增加 DocumentFilter 隐藏不需要显示的接口
services.ConfigureSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1& ...
- 简单的js验证码
转自:未找到 <script type ="text/javascript" language ="javascript"> var cod ...