开始网络流的学习,更新一下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. 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7 - HackerEarth Problems Compilation

    B: 思路: 暴力,每两个判断一下; C: 思路: 容斥定理,先枚举脖子下面那个点和那个不可描述的点,算出所有的方案数,这里面有多的腿当成了脖子或者胳膊的,然后就再枚举这种情况把这些减去,又减多了; ...

  2. POJ2184 Cow Exhibition[DP 状态负值]

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12420   Accepted: 4964 D ...

  3. C# Interlocked 笔记

    无锁代码下,在读写字段时使用内存屏障往往是不够的.在 64 位字段上进行加.减操作需要使用Interlocked工具类这样更加重型的方式.Interlocked也提供了Exchange和Compare ...

  4. dp入门问题

    昨天晚上的rank彻底废了..一个星期没敲代码完全没手感.作为总结,贴一道昨天浪费了我两小时的dp.http://acm.dirring.com/problem.php?cid=1003&pi ...

  5. iOS多线程之NSThread详解

    在iOS中每个进程启动后都会建立一个主线程(UI线程),这个线程是其他线程的父线程.由于iOS中除了主线程,其他子线程是独立于Cocoa Touch的,所以只有主线程可以更新UI界面.iOS多线程的使 ...

  6. 微信JSSDK配置文件说明

    微信JSSDK配置文件说明 1.官方配置 wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开, ...

  7. Meet Python: little notes 2

    From this blog I will turn to Markdown for original writing. Source: http://www.liaoxuefeng.com/ ♥ l ...

  8. Microsoft.Office.Interop.Excel, Version=12.0.0.0版本高于引用的程序集(已解决)

    Microsoft.Office.Interop.Excel, Version=12.0.0.0版本高于引用的程序集(已解决) 论坛里的帮助:http://bbs.csdn.net/topics/39 ...

  9. BZOJ 1066 【SCOI2007】 蜥蜴

    Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为$1$,蜥蜴的跳跃距离是d,即蜥蜴可以跳 ...

  10. 阿里云安装LNMP以及更改网站文件和MySQL数据目录

    LNMP安装了哪些软件?安装目录在哪LNMP相关软件安装目录Nginx 目录: /usr/local/nginx/MySQL 目录 : /usr/local/mysql/MySQL数据库所在目录:/u ...