最大流的模板题

 /*
 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. 一些 Shell 脚本(持续更新)

    1. 启动日志分析 启动日志格式如下: 开机时间:2015/05/13 周三 16:45:17.79 关机时间:2015/05/13 周三 18:46:03.91 开机时间:2015/05/14 周四 ...

  2. mysql存储过程和游标以及if-else,while典型实例

    -- -------------------------------------------------------------------------------- -- Routine DDL - ...

  3. 【转】android ListView 几个重要属性

    android ListView 几个重要属性 分类: Android2012-03-08 19:25 19324人阅读 评论(5) 收藏 举报 listviewandroid活动javalistnu ...

  4. jquery实现select下拉框可输入+联想关联option

    下面代码摘自http://www.oschina.net/question/96791_12832 <script language="javascript" src=&qu ...

  5. 【转】#ifdef _DEBUG用法小结

    原文地址:http://blog.csdn.net/shijizhisheng/article/details/1908054 1 #ifdef _DEBUG virtual void AssertV ...

  6. angular 嵌套实现树结构 ng-repeat ng-include

    效果图 ang.html <!doctype html><html lang="en"><head>    <meta charset=& ...

  7. 《我是IT一只小小鸟》读后感

    <我是IT一只小小鸟>读后感 首先,非常感谢我的老师给我推荐了这么一本书,虽然刚开始因为这门课学分太低,所以我对老师布置了字数这么多的作业存在有很大的不满,但在看了这本书后我的不满立马得到 ...

  8. CSS3 3D变换

    可以这么说,3D变换是基于三维坐标系的.以下是“盗用”的图 CSS3中的3D变换主要包括以下几个功能函数: 3D位移:包括translateZ()和translate3d(): 3D旋转:包括rota ...

  9. Phyre LCUE with YEBIS cause issues about GS

    when LCUE enabled in phyreEngine when Yebis integrated and render there are two mainloopdraws in one ...

  10. 10 个让人惊讶的 jQuery 插件

    说是让人惊讶,你可能会觉得我们没见过世面,但这里提及的一些 jQuery 的插件的确平时比较少见,用的人应该更少. Grid portfolio 使用竖排方式显示条目信息,现在很流行的的内容布局方式. ...