hdoj1532Drainage Ditches(网络流)

华为Atlas 300I推理卡驱动安装避坑指南:不同安装方式的选择与优化 本文详细解析华为Atlas 300I推理卡驱动安装的三种主流方式(.run、.rpm和源码编译),提供关键环境检查步骤、安装流程优化建议及常见问题解决方案,帮助开发者高效完成芯片推理卡部署并规避典型安装陷阱。 阅读详情

Drainage Ditches

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9176    Accepted Submission(s): 4303


Problem Description
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. 
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. 
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle. 
 

Input
The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
 

Output
For each case, output a single integer, the maximum rate at which water may emptied from the pond. 
 

Sample Input
  
5 4 1 2 40 1 4 20 2 4 20 2 3 30 3 4 10
 

Sample Output
  
50
 

Source
 

Recommend
lwg   |   We have carefully selected several similar problems for you:  1533 3338 1569 3572 3416 
 

刚学网络流,这题用了两种方法敲了下,这是网络流入门的好题

ford_fulkerson和dinic

自己感觉还是 dinic效率高些



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include<stack>
using namespace std;
const int inf=10000000;
const int N=210;
struct edge{int to,cap,res;};
vector<edge> g[N];
int iter[N];
int level[N];
void init()
{
    for(int i=0;i<N;i++)
        g[i].clear();
}
void bfs(int s)
{
    memset(level,-1,sizeof(level));
    level[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=0;i<g[u].size();i++)
        {
            edge &e=g[u][i];
            if(e.cap>0&&level[e.to]<0)
            {
                level[e.to]=level[u]+1;
                q.push(e.to);
            }
        }
    }
}
int dfs(int s,int t,int f)
{
    if(s==t) return f;
    for(int &i=iter[s];i<g[s].size();i++)      // 这里用i=0开始也可以,不过这样可以优化一下
    {
        edge &e=g[s][i];
        if(e.cap>0&&level[e.to]>level[s])
        {
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0)
            {
                e.cap-=d;
                g[e.to][e.res].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
void add_edge(int from,int to,int cost)
{
    edge tmp;
    tmp.to=to;tmp.cap=cost;tmp.res=g[to].size();
    g[from].push_back(tmp);
    tmp.to=from;tmp.cap=0;tmp.res=g[from].size()-1;
    g[to].push_back(tmp);
}
int max_flow(int s,int t)
{
    int ans=0;
    for(;;)
    {
        bfs(s);
        if(level[t]<0) return ans;
        memset(iter,0,sizeof(iter));
        while(1)
        {
            int f=dfs(s,t,inf);
            if(f>0) ans+=f;
            else break;
        }
    }
}
int main()
{
    int e,v;
    while(scanf("%d%d",&e,&v)!=EOF)
    {
        init();
        for(int i=0;i<e;i++)
        {
            int aa,bb,cc;
            scanf("%d%d%d",&aa,&bb,&cc);
            add_edge(aa,bb,cc);
        }
        printf("%d\n",max_flow(1,v));
    }
    return 0;
}







#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include<stack>
using namespace std;

const int N=210;
int used[N];
struct edge{int to,cap,res;};
const int inf=10000000;
vector<edge> g[N];
int dfs(int s,int t,int f)
{
    used[s]=1;
    if(s==t) return f;
    for(int i=0;i<g[s].size();i++)
    {
        edge &e=g[s][i];
        if(e.cap>0&&!used[e.to])
        {
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0)
            {
                e.cap-=d;
                g[e.to][e.res].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
void init()
{
    for(int i=0;i<N;i++)
        g[i].clear();
}
void add_edge(int from,int to,int cost)
{
    edge tmp;
    tmp.to=to;tmp.cap=cost;tmp.res=g[to].size();      //这里要好好理解一下
    g[from].push_back(tmp);
    tmp.to=from;tmp.cap=0;tmp.res=g[from].size()-1;
    g[to].push_back(tmp);
}
int max_flow(int s,int t)
{
    int ans=0;
    for(;;)
    {
        memset(used,0,sizeof(used));
        int f=dfs(s,t,inf);
        if(f<=0)
        return ans;
        ans+=f;
    }
}
int main()
{
    int v,e;
    while(scanf("%d%d",&e,&v)!=EOF)
    {
        init();
        for(int i=0;i<e;i++)
        {
            int aa,bb,cc;
            scanf("%d%d%d",&aa,&bb,&cc);
            add_edge(aa,bb,cc);
        }
        printf("%d\n",max_flow(1,v));
    }
    return 0;
}






























































手把手教你用Docker快速部署ZLMediaKit流媒体服务器(含WebRTC配置) 本文详细介绍了如何使用Docker快速部署ZLMediaKit流媒体服务器,并配置WebRTC功能。通过容器化部署,实现环境一致性、资源隔离和快速扩展,同时提供WebRTC专项配置、多协议推拉流实战测试及生产环境优化建议,帮助开发者高效搭建企业级流媒体平台。 阅读详情

相关推荐

【树莓派4B】八、树莓派软路由,Ubuntu18.04配置路由转发

我的目的是通过把树莓派做成一个软路由,相当于一个智能路由器。 材料 树莓派4B,操作系统其实可以是其他的Linux版本。以为4B自带无线网卡,就用自带无线网卡作为路由出口。 大概思路 具体步骤 配置两个网卡的IP sudo vim /etc/network/interface 这里设置静态IP,也可以动态获取。 #Local loopback auto lo iface lo inet loopback #Ethernet0 auto eth0 iface eth0 inet static addr

林愿留的博客 10万+

最大网络流(Dinic)

hdu1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8043    Accepted Submission(s): 3756 Problem Description

PSQ的专栏 680

三大主流交易接口实战指南:XTP、CTP与数字货币API的实盘接入解析

本文深入解析了量化交易系统实现实盘交易的关键环节,聚焦于三大主流交易接口的实战接入。详细介绍了证券领域的XTP、期货领域的CTP以及数字货币交易所API的核心特性、代码封装要点与风控实践,并提供了多市场接口整合的统一架构方案,为开发者打通量化交易的“最后一公里”提供了一份接地气的实战指南。

win55的博客 1376

HDOJ---1532||POJ---1273 Drainage Ditches[最大流-模版]

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4515    Accepted Submission(s): 2108 Problem Description Every time it rains...

weixin_33796177的博客 138

蓝牙开发实战:如何用Wireshark抓取HCI协议包(附完整分析步骤)

本文详细介绍了如何使用Wireshark抓取和分析蓝牙HCI协议包,包括环境搭建、过滤器配置技巧、数据包深度解析及高级调试方法。通过实战案例,帮助开发者快速定位蓝牙连接问题,提升调试效率。

cuda7parallel的博客 1148

遥感图像地物覆盖分类,数据集制作-分类模型对比-分类保姆级教程

1.新建shp文件地理坐标系保持和影像一致,面类型2.打开属性表3.添加字段这里分类6类,点击添加值添加添加完毕开始人工选地物类型,制作数据集开始标注,标注的时候可以借助谷歌地图来看标记足够多的样本打开面转栅格工具设置nodata值为15。

热爱分享,热爱记录 2526

hdoj 1532 Drainage Ditches 题解(最大流)

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7845    Accepted Submission(s): 3659 Problem Description Every tim

大神养成中..... 7168

【AI大模型:前沿】41、建筑行业大模型创业全指南:从技术突破到成本控制与落地路径

建筑行业大模型是“高门槛、高回报”的长周期赛道,适合有建筑行业资源+AI技术背景的团队切入。数据是基础,场景切割是策略,合规是底线。通过聚焦“设计生成+规范审查”等刚需场景,用“仿真数据+开源模型”降低成本,3-5年内有望成长为行业独角兽。对于中小团队,避开千万级全流程模型的红海,深耕“小而美”的单点工具,同样能实现盈利与快速扩张。关键成功公式建筑AI创业 = 50%数据壁垒构建 + 30%场景精准切入 + 20%成本控制能力。

2025博客之星Top81。专注AI工程化与架构实战。从分布式思维到模型部署,用工程化视角为你厘清AI落地的真实路径。 2114

hdoj--1532 Drainage Ditches(网络流/最大流)

hdoj 1532题解#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> using namespace std;const int maxn = 200 + 10; const int inf = 0x7fffffff;st

许少y 509

【思考模型框架】前景理论(Prospect Theory),认为人们并不是完全理性的决策者,而是根据一些心理上的偏差来评估选项的价值

前景理论,是一种行为经济学理论。前景理论,描述了人们在不确定条件下如何作出决策。前景理论,认为人们并不是完全理性的决策者,而是根据一些心理上的偏差来评估选项的价值。

奶爸的编程之路,也就一周冷个三天 1643

【导航理论&实战篇】四足机器人弹簧倒立摆(SLIP)动力学模型

认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长!本文先对四足机器人动力学模型-VMC、SLIP和浮动机体模型做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章四足机器人弹簧加载倒立摆(SLIP)动力学模型是一种用于描述和分析四足机器人在运动过程中动态特性的理论模型。这种模型将四足机器人的腿部简化为弹簧,而机器人的身体则被视为一个倒立摆,这样的抽象使得研究者能够更容易地分析和控制机器人的运动。提示:以下是本篇文章正文内容。

qq_35635374的博客 806

hdoj 1532 Drainage Ditches

题目:Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus,

lizhb5的博客 401

Windows VHD的新玩法——设置任意挂载点

vhd 挂载隐藏的虚拟分区 详细过程 分别使用CreateVirtualDisk和OpenVirtalDisk来创建和打开虚拟磁盘文件。 使用AttachVirtualDisk,必须具有管理员权限才能成功执行此步骤。 初始化设备(延时Sleep),获取附加 VHD 的 UNC 路径:\\.\PhysicalDrive# 。 使用FindFirstVolume/FindNextVolume枚举已安装的卷以查找虚拟磁盘上的卷。 使用SetVolumeMountPoint将卷挂载到文件夹或者设

圣三一 2587

HDOJ 1532 Drainage Ditches 初探网络流之最大流(入门)

HDOJ 1532 Drainage Ditches 网络流对于刚入门算法学习的同学来说是稍有困难的(比如我),于是我打算从一道最基本的最大流例题让自己好好的学习一下网络流。这一篇文章是完完全全的新手入门文章,对于有些许基础的人可能不会有什么帮助,而对于小白来说,可能是叩开网络流的一个起点吧 题目大意 给出n与m,n为有向边数,m为顶点数,求s到t的最大流。 什么是最大流呢?不妨先来看一下题目的i...

siberiaHLY的博客 368

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

hdoj 1532 Drainage Ditches(最大网络流)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用EdmondsKarp算法求解; 需要注意输入的边中可能有重边的存在; 代码如下: #include <queue> #include <vector> #i...

aqjh9999的博客 123

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

最大网络流dinic算法—【hdoj1532】Drainage Ditches

题目hdoj1532传送门 落谷传送门 题意:给出n个河流,m个点,以及每个河流的流量,求从1到m点的最大流量。 Sample Input: 5 4 1 2 40 1 4 20 2 4 20 2 3 30 3 4 10Sample Output: 50dinic算法每次都先bfs一遍,处理出一个层次图,然后dfs就可以多次用到这个图,相比EK每次都建一个图要快。并且层次图是最短路

struct_liao的博客 358

HDOJ-1532 Drainage Ditches(网络流)

#include #include #include #include using namespace std; const int MAXN=205; const int MAXE=205; const int INF=0X3F3F3F3F; struct Edge { int to,next,cap,flow; }edge[MAXE]; int tol; int head

GoldMoon 622

hdoj 1532 Drainage Ditches 题解(网络流 >最大流详解)

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22614    Accepted Submission(s): 10830   Problem Description Every time it ...

qq_41668093的博客 247

HDOJ 1532 Drainage Ditches

题意:有一个n个点和m条边的网络,每条边都有流量上限,求从点1到点n的最大流量 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路:网络流dinic模板 注意点:无 以下为AC代码: Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory

luminous11的专栏 538

【HDOJ 1532】 Drainage Ditches(最大流模板)

【HDOJ 1532】 Drainage Ditches(最大流模板)

ACMer' 1927

hdoj 1532 Drainage Ditches (最大流)

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 53 Accepted Submission(s): 44   Problem Description

1988的博客 317

HDU 1532 Drainage Ditches 最大流

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9339    Accepted Submission(s): 4402 Problem Description Every time it

小人物的草稿本 705

hdoj 1532 Drainage Ditches 【最大流---裸题】

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15420    Accepted Submission(s): 7350 Problem Description Every ti

leibniz_zhang的博客 422

HDOJ 1532 Drainage Ditches (Ford-Fulkerson + EK + Dinic)

DrainageDitches Time Limit: 2000/1000 MS(Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16953    Accepted Submission(s): 8019 Problem Description Every time it

Dust_heart的博客 563

HDOJ 1532 Drainage Ditches(最大流)

/* AC,一道基本最大流问题,采用Edmonds_Karp算法,算法复杂度O(V*E*E) */ #include &lt;iostream&gt; #include &lt;queue&gt; using namespace std; const int nMax = 207; const int INF = 0x7fffffff; queue&lt;int&gt; Q; int star...

java开发指南博客 【转载】 72

【网络流第二步】Hdu 1532——Drainage Ditches 邻接矩阵版

不多说,HDU卡数据还是挺厉害的 #include #include #include #include #include #include #include #define maxn 205 #define INF 100000000 using namespace std; //Template Bade By: Xiaobin Chen int pointnum,

圣人不仁,使草胜豆苗稀。 761
上一篇: poj2387Til the Cows Come Home(dijkstra)
下一篇: hdoj2767 Proving Equivalences(强连通分量+缩点)
IT旅行
博客等级 码龄12年 3粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值