开始网络流的学习,更新一下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. 《你不常用的c#之二》:略谈GCHandle

    我们在使用c#托管代码时,内存地址和GC回收那不是我们关心的,CLR已经给我们暗箱操作.但是如果我们在c#中调用了一个非托管代码,比如vc的DLL,而且他有个回调函数,需要引用c#中的某个对象并操作, ...

  2. 在VMware Workstation上安装CentOS6.5系统步

    在VMware Workstation上安装CentOS6.5系统步骤 听语音 | 浏览:147 | 更新:2016-07-28 15:45 | 标签:安装 虚拟机 CENTOS 1 2 3 4 5 ...

  3. tyvj1098[luogu 2365]任务安排 batch

    题目描述 N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分批加工,第i个任务单独完成所需的时间是Ti.在每批任务开始 ...

  4. hashmap先按照value从大到小排序,value相等时按照key从小到大排序

    hashmap先按照value从大到小排序,value相等时按照key从小到大排序. [2]是从小到大排序,在[2]代码基础上交换o1,o2位置即可. 代码中用到[1]中提到的在value相等时再比较 ...

  5. Android入门篇1-Hello World

    一.android studio安装. 二.项目结构 三.运行流程 src->main->AndroidMainifest.xml注册HelloWorldActivity(intent-f ...

  6. C语言--指向多维数组的指针和指针数组

    #include <stdio.h> //void show(char *p[]); ]); int main(){ ][]={","abc","x ...

  7. Laterality issue on fMRI image

    The laterality issue: different software will interpret fMRI images in different way (mainly refer t ...

  8. Elasticsearch-2.3.x填坑之路

    使用版本说明:2.3.2 强制不能使用root用户启动?因为在2.x版本强调了安全性,防止attracker侵入root用户,所以建议使用者创建其他用户启动.当然,可以通过配置来实现root用户启动. ...

  9. codevs3145 汉诺塔问题

    难度等级:白银 3145 汉诺塔问题 题目描述 Description 汉诺塔问题(又称为河内塔问题),是一个大家熟知的问题.在A,B,C三根柱子上,有n个不同大小的圆盘(假设半径分别为1-n吧),一 ...

  10. struts2 异常处理3板斧

    板斧1:找不到action的错误 在struts.xml中参考如下配置 <struts> ... <package name="default" namespac ...