开始网络流的学习,更新一下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模板题的更多相关文章

  1. Codevs 1993 草地排水

    1993 草地排水 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地 ...

  2. codevs 1993草地排水

    1993 草地排水

  3. 模板题 codevs 1993 草地排水 想学习的请看链接

    不能再水的题了. Dinic算法,比EK更快. 想要学习请看链接   https://comzyh.com/blog/archives/568/ 并附上我的模板(其实和comzyh大神的一样) #in ...

  4. codevs 1993 草地排水 USACO

    /*Dinic*/ #include<iostream> #include<cstdio> #include<cstring> #include<queue& ...

  5. HDU 4280:Island Transport(ISAP模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...

  6. CODEVS——T 1993 草地排水 USACO

    http://codevs.cn/problem/1993/  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 De ...

  7. 【CodeVS】1993草地排水

    题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水 ...

  8. 【最大流】【CODEVS】1993 草地排水

    [算法]网络流-最大流(dinic) [题解]http://www.cnblogs.com/onioncyc/p/6496532.html #include<cstdio> #includ ...

  9. AC日记——热浪 codevs 1557 (最短路模板题)

    1557 热浪  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...

随机推荐

  1. Stanford机器学习笔记-8. 支持向量机(SVMs)概述

    8. Support Vector Machines(SVMs) Content 8. Support Vector Machines(SVMs) 8.1 Optimization Objection ...

  2. POJ2796Feel Good[单调栈]

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 13376   Accepted: 3719 Case T ...

  3. Gvr SDK for Unity 分析(二)

    前言 关于google vr sdk的具体使用,传送门 Gvr SDK for Unity 分析(一) Google Daydream平台已经整合进Google VR SDK 本文环境:Unity5. ...

  4. ORCHARD 是什么?

    官网 http://orchard.codeplex.com 教程 http://www.cnblogs.com/sunjunlin/p/3876693.html [翻译]从头开始编写一个Orchar ...

  5. 常用Meta整理

    标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他web 服务. ——W3School 必要属性 ...

  6. 实用js函数收集

    1. 全选复选框: //复选框全选函数 function SelectAll() { var checkAll = document.getElementsByName("checkAll& ...

  7. Android爬坑之旅:软键盘挡住输入框问题的终极解决方案

    前言 开发做得久了,总免不了会遇到各种坑.而在Android开发的路上,『软键盘挡住了输入框』这个坑,可谓是一个旷日持久的巨坑--来来来,我们慢慢看. 入门篇 Base 最基本的情况,如图所示:在页面 ...

  8. 阿里云消息队列MQ_HTTP接入 for .NetCore 简单例子

    , , )).TotalMilliseconds;                 , , )).TotalMilliseconds;                 )                ...

  9. 转:用WCAT进行IIS压力测试

    Microsoft的Web容量分析工具(WCAT) 是测试你的客户-服务器网络配置的必备工具.这个工具在你的网络上对多种工作量的场景进行仿真,允许你确定你的网络和服务器的最佳配置.WCAT是专门为 评 ...

  10. C++ 中dynamic_cast&lt;&gt;的使用方法小结 -判断类型-rtti

    将一个基类对象指针(或引用)cast到继承类指针,dynamic_cast会根据基类指针是否真正指向继承类指针来做相应处理          即会作一定的判断.        对指针进行dynamic ...