HDU 1532 Drainage Ditches——最大流EK算法
来源:互联网 发布:w7内外网转换软件 编辑:程序博客网 时间:2024/05/29 15:59
模板题
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 1000 + 10;struct Node { int to; int cap; int rev;};vector<Node> v[maxn];bool used[maxn];void add_node(int from, int to, int cap) { v[from].push_back((Node){to, cap, v[to].size()}); v[to].push_back((Node){from, 0, v[from].size() - 1});}int dfs(int s, int t, int f) { if (s == t) return f; used[s] = true; for (int i = 0; i < v[s].size(); i++) { Node &temp = v[s][i]; if (used[temp.to] == false && temp.cap > 0) { int d = dfs(temp.to, t, min(f, temp.cap)); if (d > 0) { temp.cap -= d; v[temp.to][temp.rev].cap += d; return d; } } } return 0;}int max_flow(int s, int t) { int flow = 0; while (true) { memset(used, false, sizeof(used)); int f = dfs(s, t, INF); if (f == 0) return flow; flow += f; }}int main(){ int n, m; while (scanf("%d %d", &n, &m) == 2) { memset(v, 0, sizeof(v)); for (int i = 0; i < n; i++) { int x, y, z; scanf("%d %d %d", &x, &y, &z); add_node(x, y, z); } printf("%d\n", max_flow(1, m)); } return 0;}
阅读全文
0 0
- HDU 1532 Drainage Ditches——最大流EK算法
- hdu 1532 Drainage Ditches (最大流—EK算法)
- hdu 1532 Drainage Ditches (最大流EK算法)
- hdu 1532 Drainage Ditches(最大流ek+dinic)
- hdu 1532 Drainage Ditches(EK算法)
- hdu 1532 Drainage Ditches 网络最大流模板 EK + Dinic两种算法AC
- HDU ACM 1532 Drainage Ditches->网络最大流模版题(EK算法实践)
- HDU 1532-Drainage Ditches(网络最大流,EK,Ford-Fulkerson,dinic3种算法套模板)
- HDU 1532 Drainage Ditches(最大流+EK算法模板题)
- poj 1273 Drainage Ditches(最大流的EK算法模板)
- hdu1532--Drainage Ditches(最大流(EK算法))
- hdu 1532 poj 1273 Drainage Ditches (ek算法)
- poj 1273 & hdu 1532 Drainage Ditches(最大流 )EK,dinic模板
- hdu 1532 Drainage Ditches (最大流 : EK && Dinic &&Dinic 当前弧优化)
- hdu 1532 Drainage Ditches(最大流 三种模板:EK、Dinic、isap)
- poj1273 Drainage Ditches 最大流EK
- hdu1532 Drainage Ditches--最大流ek
- hdu1532-Drainage Ditches(最大流&EK)
- JAVA并行流导致的 No thread-bound request found
- Linux---RH254---unit 6 NFS
- hdu 5971 Wrestling Match 判断能否构成二分图 [Problem A]2016ACM/ICPC亚洲区大连站
- Netty异步IO和回调函数
- Android---------HttpURLConnection的 get 请求和 post 请求(更容易理解)
- HDU 1532 Drainage Ditches——最大流EK算法
- phpcms v9网站搬家更换域名的方法
- VS调试网站时分析器错误
- 059、060、061-C++
- mac效率工具之moom
- [Leetcode] 198. House Robber 解题报告
- OpenCV学习笔记(23)findContours与drawContours
- java中通过反射获取成员方法并使用
- Ubuntu 14.04 LTS 安装 Virtualenvwrapper