HDU - 1532

题意:有m个点,n条管道,问从1到m最大能够同时通过的水量是多少?

题解:最大流模板题。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 0x3ffffff;
const int maxn = 205;
int gra[maxn][maxn];
int flow[maxn];
int path[maxn];
int n,m; int bfs(int s, int e)
{
queue<int>q;
int t;
memset(path,-1,sizeof(path));
memset(flow,0,sizeof(flow));
path[s] = 0;
flow[s] = INF;
q.push(s);
while(!q.empty()){
t = q.front();
q.pop();
if(t == e) break;
for(int i = 1; i <= m; i ++)
{
if(i != s && gra[t][i] && path[i] == -1)
{
flow[i] = flow[t] < gra[t][i] ? flow[t] : gra[t][i];
path[i] = t;
q.push(i);
}
}
}
if(path[e] == -1)
return -1;
else return flow[e];
} int EK(int s, int e){
int maxflow = 0;
int pre, now, step;
while((step = bfs(s,e))!= -1){
maxflow += step;
now = e;
while(now != s){
pre = path[now];
gra[pre][now] -= step;
gra[now][pre] += step;
now = pre;
}
}
return maxflow;
}
int main()
{ int u,v,c;
while(~scanf("%d%d",&n,&m)){
memset(gra,0,sizeof(gra));
for(int i = 1; i <= n; i ++)
{
scanf("%d %d %d", &u,&v,&c);
gra[u][v] += c;
}
int ans = EK(1,m);
printf("%d\n",ans);
}
return 0;
}

Drainage Ditches (HDU - 1532)(最大流)的更多相关文章

  1. HDU 1532 最大流入门

    1.HDU 1532 最大流入门,n个n条边,求第1点到第m点的最大流.只用EK做了一下. #include<bits/stdc++.h> using namespace std; #pr ...

  2. hdu 1532(最大流)

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

  3. HDU 1532 最大流模板题

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1532 最近在学网络流,学的还不好,先不写理解了,先放模板... 我觉得写得不错的博客:http://blo ...

  4. poj 1273 ---&&--- hdu 1532 最大流模板

    最近在换代码布局,因为发现代码布局也可以引起一个人的兴趣这个方法是算法Edmonds-Karp 最短增广路算法,不知道的话可以百度一下,基于Ford-Fulkerson算法的基础上延伸的 其实我不是很 ...

  5. hdu 1532 最大流

    #include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...

  6. HDU 1532||POJ1273:Drainage Ditches(最大流)

    pid=1532">Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

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

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

  8. poj 1273 && hdu 1532 Drainage Ditches (网络最大流)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53640   Accepted: 2044 ...

  9. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

随机推荐

  1. Qt中容器类应该如何存储对象(最好使用对象指针类型,如:QList<TestObj*>,而不要使用 QList<TestObj> 这样的定义,建议采用 智能指针QSharedPointer)

    Qt提供了丰富的容器类型,如:QList.QVector.QMap等等.详细的使用方法可以参考官方文档,网上也有很多示例文章,不过大部分文章的举例都是使用基础类型:如int.QString等.如果我们 ...

  2. 微信小程序页面滚动到指定位置

    页面上有一个元素或者组件,id 为 comment 则: var me = this; var query = wx.createSelectorQuery().in(me); query.selec ...

  3. (九)shiro之web集成

    Url 匹配方式? 匹配一个字符 /admin? 可以匹配/admin1 或者/admin2 但是不能匹配/admin12 或者/admin* 匹配零个或者一个或者多个字符 /admin* 可以匹配 ...

  4. php 环境搭建问题

    项目过程中需要用到 PHP环境 https://www.cnblogs.com/cyrfr/p/6483529.html APACHE无法启动:THE REQUEST OPERATION HAS FA ...

  5. tornado基本使用一

    一.tornado web程序编写思路 . 创建web应用实例对象,第一个初始化参数为路由映射列表 . 定义实现路由映射列表中的handler类 . 创建服务器实例, 绑定服务器端口 . 启动当前线程 ...

  6. 【Zookeeper】 在Java中的操作

    一.基本功能演示 1.1 Maven依赖信息 1.2 代码演示 方法说明 1.3 创建Zookeeper节点信息 二.Watcher 2.1 什么是Watcher接口 2.2 Watcher代码 一. ...

  7. 阿里Java架构师打包 FatJar 方法小结

    在函数计算(Aliyun FC)中发布一个 Java 函数,往往需要将函数打包成一个 all-in-one 的 zip 包或者 jar 包.Java 中这种打包 all-in-one 的技术常称之为 ...

  8. c#创建目录和文件夹,数据写入并生成txt文件

    c#创建目录: // 获取程序的基目录.System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径.System.Diagnostics.Pro ...

  9. 用cef Python打造自己的浏览器

    背景 项目需要做一个客户端的壳,内置浏览器,访问指定 的url 采用技术 python3.5 cefpython https://github.com/cztomczak/cefpython#inst ...

  10. SpringCloud各个组件通俗解析

    https://www.cnblogs.com/lonelyJay/p/9936241.html