#include <iostream>
#include <queue>
using namespace std;
int G[][];
int Prev[]; //路径上每个节点的前驱节点
bool Visited[];
int n,m; //m是顶点数目,顶点编号从1开始 1是源,m是汇, n是 边数 int Augment()
{
int v;
int i;
deque<int> q;
memset(Prev,,sizeof(Prev));
memset(Visited,,sizeof(Visited));
Prev[] = ;
Visited[] = ;
q.push_back();
bool bFindPath = false;
//用bfs寻找一条源到汇的可行路径
while (!q.empty())
{
v = q.front();
q.pop_front();
for (i = ; i <= m; i++)
{
if (G[v][i] > && Visited[i] == )
{
//必须是依然有容量的边,才可以走
Prev[i] = v;
Visited[i] = ;
if( i == m )
{
bFindPath = true;
q.clear();
break;
}
else
q.push_back(i);
}
}
} if (!bFindPath)
return ;
int nMinFlow = ;
v = m; //寻找源到汇路径上容量最小的边,其容量就是此次增 加的总流量
while( Prev[v] )
{
nMinFlow = min( nMinFlow,G[Prev[v]][v]);
v = Prev[v];
}
//沿此路径添加反向边,同时修改路径上每条边的容量
v = m;
while( Prev[v] )
{
G[Prev[v]][v] -= nMinFlow;
G[v][Prev[v]] += nMinFlow;
v = Prev[v];
}
return nMinFlow;
} int main()
{
while (cin >> n >> m)
{
//m是顶点数目,顶点编号从1开始
int i,j,k;
int s,e,c;
memset( G,,sizeof(G));
for( i = ;i < n;i ++ )
{
cin >> s >> e >> c;
G[s][e] += c; //两点之间可能有多条边
}
int MaxFlow = ;
int aug;
while( aug = Augment() )
MaxFlow += aug;
cout << MaxFlow << endl;
}
return ;
}

poj1273 Drainage Ditches 基础网络流的更多相关文章

  1. POJ1273 Drainage Ditches (网络流)

                                                             Drainage Ditches Time Limit: 1000MS   Memor ...

  2. [Poj1273]Drainage Ditches(网络流)

    Description 给图,求最大流 最大流模板题,这里用dinic Code #include <cstdio> #include <cstring> #include & ...

  3. poj1273 Drainage Ditches Dinic最大流

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 76000   Accepted: 2953 ...

  4. 【网络流】POJ1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78671   Accepted: 3068 ...

  5. poj-1273 Drainage Ditches(最大流基础题)

    题目链接: Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67475   Accepted ...

  6. poj1273 Drainage Ditches

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

  7. POJ 1273 Drainage Ditches(网络流,最大流)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  8. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. POJ_1273 Drainage Ditches 【网络流】

    一.题面 Drainage Ditches 二.分析 网络流的裸题. 1 Edmonds-Karp算法 求解网络流其实就是一个不断找增广路,然后每次找到一条增广路后更新残余网络的一个过程. EK算法主 ...

随机推荐

  1. FSB总线、HT总线、QPI总线、DMI总线

    http://wenku.baidu.com/link?url=d0NQFyvVpU--FpQUIjkPcdE036riitKgKib3385qr7VdB1oNUcIDpRndY-HH4ITjzJln ...

  2. Cookie 和 Session 的区别 与联系

    一. 概念理解 你可能有留意到当你浏览网页时,会有一些推送消息,大多数是你最近留意过的同类东西,比如你想买桌子,上淘宝搜了一下,结果连着几天会有各种各样的桌子的链接.这是因为 你浏览某个网页的时候,W ...

  3. python -- day 11 考试题

    1. 文件t1.txt里面的内容为:(6分) 1,alex,22,13651054608,IT 2,wusir,23,13304320533,Tearcher 3,taibai,18,13332353 ...

  4. app上架的问题

    1..p12证书文件(钥匙串导出)开发证书和描述文件的 2.app打包好重Xcode上传到iTunes中的时候最好做校验: 3.程序跑真机出现的问题 解决方法:debug 模式改成release模式 ...

  5. yarn笔记

    常用命令: 创建项目:yarn init 安装依赖包:yarn == yarn install 添加依赖包:yarn add Yarn命令列表 命令 操作 参数 标签 yarn add 添加依赖包 包 ...

  6. MapReduce Join的使用

    一.Map端Join 可连接两个都非常大的数据集之间可使用map端连接,数据在到达map端之前就执行连接操作. 需满足: 两个要连接的数据集都先划分成相同数量的分区,相同的key要保证在同一分区中(每 ...

  7. oracle 转移表空间

    一.系统表空间数据文件迁移:SQL> conn /@tmpdb as sysdba 已连接. SQL> desc dba_data_files; 名称 是否为空? 类型 --------- ...

  8. solr安装-tomcat+solrCloud构建稳健solr集群

    solrCloud的搭建可以有两种方式:使用solr内嵌的jetty来搭建:使用外部web容器tomcat来搭建.对于使用jett来搭建参考solr官方的手册照着做肯定ok,下面我主要讲的是如何使用t ...

  9. 「HAOI2015」「LuoguP3178」树上操作(树链剖分

    题目描述 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中所有点的点权都增 ...

  10. COCOS2DX场景切换特效

    cocos2d-x 3.0中场景切换特效比较多,而且游戏开发中也经常需要用到这些特效,来使场景切换时不至于那么干巴,遂这里汇总一下,开发中使用. 百牛信息技术bainiu.ltd整理发布于博客园 场景 ...