最大流的模板题

 /*
 ID: yingzho1
 LANG: C++
 TASK: ditch
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>
 #include <cstdio>
 #include <cstdlib>
 #include <limits>
 #include <stack>

 using namespace std;

 ifstream fin("ditch.in");
 ofstream fout("ditch.out");

 ;
 ;

 int N, M;
 int g[MAX][MAX], f[MAX][MAX], pre[MAX], inc[MAX];

 bool bfs(int s, int d) {
     queue<int> que;
     ; i <= M; i++) pre[i] = -;
     que.push(s);
     inc[s] = INF;
     while (!que.empty()) {
         int u = que.front();
         que.pop();
         ; i <= M; i++) {
              && f[u][i] < g[u][i]) {
                 inc[i] = min(inc[u], g[u][i]-f[u][i]);
                 pre[i] = u;
                 if (i == d) return true;
                 que.push(i);
             }
         }
     }
     return false;
 }

 int edmond_karp(int s, int d) {
     ;
     while (bfs(s, d)) {
         maxflow += inc[d];
         for (int i = d; i != s; i = pre[i]) {
             f[pre[i]][i] += inc[d];
             f[i][pre[i]] -= inc[d];
         }
     }
     return maxflow;
 }

 int main()
 {
     fin >> N >> M;
     int s, d, e;
     ; i < N; i++) {
         fin >> s >> d >> e;
         g[s][d] += e;
     }
     fout << edmond_karp(, M) << endl;

     ;
 }

USACO Section 4.2: Drainage Ditches的更多相关文章

  1. USACO Section 4.2 Drainage Ditches(最大流)

    最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...

  2. POJ1273 USACO 4.2.1 Drainage Ditches CodeVS1993草地排水 网络流 最大流 SAP

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 传送门 - POJ 传送门 - CodeVS 题意概括 给出一个图,告诉你边和容量,起点是1,汇点是n,让你求最大流. 题解 ...

  3. USACO 4.2 Drainage Ditches(网络流模板题)

    Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...

  4. POJ 1273 Drainage Ditches题解——S.B.S.

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67823   Accepted: 2620 ...

  5. poj1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68414   Accepted: 2648 ...

  6. Drainage Ditches(dinic)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59210   Accepted: 2273 ...

  7. Drainage Ditches

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu-----(1532)Drainage Ditches(最大流问题)

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)

    Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...

随机推荐

  1. 通过HTML5获取当前位置

    // 当前位置 function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPositi ...

  2. 学习Linux第六天

    1.Shell编程 bash变量: 都是以字符串格式存储 x=5 等号左右不能有空格,会当作命令处理 如何调用: echo $x 此法无法进行数值运算,不存在的变量输出空 set -u 设置变量报错 ...

  3. yii的常用配置文件

    <?php return array( 'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..', //当前应用根目录路径 'nam ...

  4. WWDC2014 debugging_in_xcode_6 总结

    1.GCD的waiting queue 可以在Xcode左侧的面板中查看. 2.可以对View进行debug类似reveal. 3.查看运行时的对象,对于自定义对象可以实现- (id)debugQui ...

  5. TEST ON 平安夜

    1.前言 = = 感觉自己其实没发过关于考试的博客过... 今天是一个平安的夜晚,漆黑的夜被霓虹划分成网络,很适合发题. 2.num9九数码问题 传统8数码改一下...只询问一个状态,所以很容易搞,正 ...

  6. Ubuntu 字体修改以及字体的相关知识 分类: ubuntu 2014-06-19 21:46 81人阅读 评论(0) 收藏

    Ubuntu chrome 字体修改 打开任意一张含有输入框的网页,比如Google首页,然后右键点击"搜索框"会拉出一个菜单,我们这样选: 拼音检查选项==>语言设置==& ...

  7. 使用JFinal-weixin配置微信开发

    先扯点闲话,申请好公众号后,一直因为没有域名.没有外网IP而没有尝试过开发微信服务.后来发现nat123可以从内网直接映射到外网,但是nat123需要钱或者T币大于0,于是为了赚一个T币,签到灌水了一 ...

  8. 测试c语言函数调用性能因素之测试三

    函数调用:即调用函数调用被调用函数,调用函数压栈,被调用函数执行,调用函数出栈,调用函数继续执行的一个看似简单的过程,系统底层却做了大量操作. 操作: 1,               调用函数帧指针 ...

  9. javascript 注意事项

    1.submit input 标签的 type里的submit是提交表单的按钮 提交时应注意 为 标签加上 “name=""”字段和form标签,才能达到想要的效果  2.正则表达 ...

  10. POJ 1665

    #include<iostream>//chengdacaizi 08.11.12 #include<iomanip> #define p 3.1415927 using na ...