hdu1532 sap模板

[译]网络流Dinic算法-最大流-HDU1532&POJ1273 POJ1273 HDU1532 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 51941   Accepted: 19732 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就 阅读详情

之前在做好多题 都用dicnic和E-K算法 

结果连续T了好几天一道题也没过

直到知道还有SAP算法

就直接摘了kuangbin的模板

在网上找了好多的模板 发现还是kuangbin的最好用

用裸题hdu1532上代码

Drainage Ditches

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


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

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<stack>
#include<queue>
#include<cmath>
#include<stack>
#include<list>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const int MAXN=20010;//点数的最大值
const int MAXM=880010;//边数的最大值
const int INF=0x3f3f3f3f;

struct Node
{
    int from,to,next;
    int cap;
}edge[MAXM];
int tol;
int head[MAXN];
int dep[MAXN];
int gap[MAXN];//gap[x]=y :说明残留网络中dep[i]==x的个数为y

int n;//n是总的点的个数,包括源点和汇点

void init()  //在main函数的开头写init别忘了!
{
    tol=0;
    memset(head,-1,sizeof(head));
}

void addedge(int u,int v,int w)
{
    edge[tol].from=u;
    edge[tol].to=v;
    edge[tol].cap=w;
    edge[tol].next=head[u];
    head[u]=tol++;
    edge[tol].from=v;
    edge[tol].to=u;
    edge[tol].cap=0;
    edge[tol].next=head[v];
    head[v]=tol++;
}
void BFS(int start,int end)
{
    memset(dep,-1,sizeof(dep));
    memset(gap,0,sizeof(gap));
    gap[0]=1;
    int que[MAXN];
    int front,rear;
    front=rear=0;
    dep[end]=0;
    que[rear++]=end;
    while(front!=rear)
    {
        int u=que[front++];
        if(front==MAXN)front=0;
        for(int i=head[u];i!=-1;i=edge[i].next)
        {
            int v=edge[i].to;
            if(dep[v]!=-1)continue;
            que[rear++]=v;
            if(rear==MAXN)rear=0;
            dep[v]=dep[u]+1;
            ++gap[dep[v]];
        }
    }
}
int SAP(int start,int end)
{
    int res=0;
    BFS(start,end);
    int cur[MAXN];
    int S[MAXN];
    int top=0;
    memcpy(cur,head,sizeof(head));
    int u=start;
    int i;
    while(dep[start]<n)
    {
        if(u==end)
        {
            int temp=INF;
            int inser;
            for(i=0;i<top;i++)
               if(temp>edge[S[i]].cap)
               {
                   temp=edge[S[i]].cap;
                   inser=i;
               }
            for(i=0;i<top;i++)
            {
                edge[S[i]].cap-=temp;
                edge[S[i]^1].cap+=temp;
            }
            res+=temp;
            top=inser;
            u=edge[S[top]].from;
        }
        if(u!=end&&gap[dep[u]-1]==0)//出现断层,无增广路
          break;
        for(i=cur[u];i!=-1;i=edge[i].next)
           if(edge[i].cap!=0&&dep[u]==dep[edge[i].to]+1)
             break;
        if(i!=-1)
        {
            cur[u]=i;
            S[top++]=i;
            u=edge[i].to;
        }
        else
        {
            int min=n;
            for(i=head[u];i!=-1;i=edge[i].next)
            {
                if(edge[i].cap==0)continue;
                if(min>dep[edge[i].to])
                {
                    min=dep[edge[i].to];
                    cur[u]=i;
                }
            }
            --gap[dep[u]];
            dep[u]=min+1;
            ++gap[dep[u]];
            if(u!=start)u=edge[S[--top]].from;
        }
    }
    return res;
}
int main()
{
     int i,j,k;
     int m;
    while(scanf("%d%d",&m,&n)==2)
    {
        init();

        int t;
        int x,y;
        while(m--)
        {

            scanf("%d%d%d",&x,&y,&t);
            addedge(x,y,t);
        }
        int  source=1;
        int sink=n;
        t=SAP(source,sink);
        printf("%d\n",t);
    }
    return 0;
}



YOLOv11改进策略【Backbone/主干网络】|替换HGNetV2骨干,包含RT-DETR中的l、x模型 本文记录的是基于HGNetv2的YOLOv11目标检测改进方法研究。本文利用HGNetv2替换YOLOv11的骨干网络,HGNetv2 通过其 GPU 推理友好的 3×3 标准卷积和层次化 HG Block 结构,能够为骨干网络提供高效且完整的特征提取能力。并且其中的和可在降低计算量的同时丰富特征表达,增强对多尺度目标特征的捕获能力,进而提高模型精度。本文配置了原论文中rtdetr-lrtdetr-x,以满足不同算力和检测精度的需求。 阅读详情

相关推荐

夜间灯光遥感数据介绍及下载汇总

夜间灯光遥感数据介绍及下载汇总

qq_43874102的博客 1万+

别再到处找离线包了!Visual Studio 2022 企业版/社区版离线安装保姆级教程(含工作负载选择指南)

本文提供Visual Studio 2022企业版/社区版离线安装的详细教程,包括工作负载选择指南和批量安装优化策略。针对网络隔离或带宽受限环境,介绍如何制作离线安装包、选择合适的工作负载组合,并分享高级技巧如增量更新和自动化部署,帮助团队高效统一开发环境配置。

weixin_28745821的博客 755

hdu 1532(最大流)

解题思路: 这是一道典型的模板题,直接套用EK算法即可。。。我感觉最大流的本质就是能否找到一个从源点到汇点的增广路径,并将其最小的边作为增加值,沿着增广路上的边进行更新。 AC: #include #include #include #include using namespace std; const int maxn = 200; const int inf = 0x7ffff

hexianhao的博客 405

eICU数据库没有ventilation_event表

各位学友大家好,我是环湖医院神经外科的飞时过,很多外院的老师和我问,ventilation_event表的问题,哪怕用ChatGPT也无法正确生成,今天我给大家用SQL做一个拿来就能用的。

环湖数据科学知识共享平台 946

微波技术仿真:微波谐振器分析_(2).微波谐振器理论

谐振器是一种能够在特定频率范围内存储和释放电磁能量的器件。在微波频段,谐振器通常用于滤波、频率选择和能量存储等应用。一个理想的谐振器在谐振频率下能够存储无限大的能量,但在实际应用中,由于损耗的存在,谐振器的性能会受到一定限制。微波谐振器在微波通信、雷达系统、微波测量和微波电路设计等领域中发挥着重要作用。谐振器的设计需要考虑多个因素,包括谐振频率的精确控制、损耗的最小化、频率稳定性的提高和小型化设计。通过理论分析和仿真工具的使用,可以有效优化谐振器的性能,满足实际应用的需求。

2401_87715305的博客 942

HDU 1532 Drainage Ditches(最大流入门题目_Edmonds-Karp 增广路算法)

一个网络是一张有向图,图中每条有向边都有一个给定的权值,成为边的容量。特别地,若则。图中还有两个指定的特殊点和分别称为源点和汇点。 设是定义在节点二元组的实数函数,且满足: 称为网络的流函数。对于,称为边的流量,成为这个边的剩余流量。 称为整个网络的流量(其中表示源点)。 E-K算法只考虑图中所有的边,用BFS找到任意一条从到的路径,同时计算出路径上各边的剩余容量的最小...

- 300

团体程序设计天梯赛竞赛题--登顶题【L3-039 攀岩】

登顶级 3 道题,每道题 30 分,满分为 90 分。

Pretty Boy Fox的博客 661

HDU-1532-网络流最大流

题目大意:求两点之间的最大流; 题目解析:思想就是迭代dfs找增广路径,直到找不到位置,注意要更新残余网络; AC代码: #include #include #include #include #include #include using namespace std; const int inf=0x3fffffff; const int maxn=1010; struct node {

zyz_3_14159的博客 388

【JTAG】1500协议详解

随着集成电路的规模不断扩大,1149.1的板级测试无法满足要求越来越高的芯片测试需求。芯片规模变大后,测试需求不在是一次测试整片芯片,而是芯片分为好几个区域去测试,而1500协议正是对1149.1在该方面的一个补充即1149.1主要测试板级间的互连,而1500用来测试芯片内不同core之间的互连。IEEEStd1500已经为包含不同模块的集成电路(ICs)开发了一种可测试性设计标准方法。............

xuhe0206的博客 7059

开源GIS -- 笔记

基础开发库 数据读写:GDAL/OGR(C/C++) ArcGIS和GE都是使用此工具 投影转换:Proj.4(C/C++) 拓扑计算:JTS(Java),GEOS(C++),Shapely(python) 组件式开发库 GeoTools(Java),DotSpatial(.NET) 空间分析: Scipy(通用科学计算、方程求解), numpy,NextworkX, rPy(统计分析), Scikit-learn,pysal(空间分析) 深度学习: Keras、 tensorflow、 pytor

DZ Space 4523

最大网络流--hdu1532

博客园首页新随笔联系订阅管理 随笔 - 103  文章 - 0  评论 - 3 最大网络流 可以这样看,图就是一种管道,管道有最大通过流量的限制,图中边的权值就是所谓的“容量”。同时,注意有唯一的源点和汇点。 这里需要注意容量和流量的区别。其中f(u,v)的范围需要额外注意,是 0 有了可行流,我们还需要求最大流

winycg的博客 590

Backtrader官方中文文档:第四章Concepts基本概念

官方Concepts章节:https://backtrader.com/docu/concepts/

汇渊科技 2606

【最大流之sap】【HDU1532】模板题

与上题一样 纯属测试模板 来自kuangbin的模板 #include #include #include #include #include #include #include #include #include #define oo 0x13131313 using namespace std; const int MAXN=200+5; const int MA

学习之路 863

蓝牙模块HM-10手册

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

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

最大流自用模板(例题:HDU1532)

三种模板:Edmonds_Karp,Dinic,SAP 例题: Drainage Ditches(HDU1532) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22365    Accepted Submission(s): 1...

Radium_1209 220

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

网络流SAP

终于决定开始学习网络流了=.= >那本书讲了很多关于求最大流的算法,然后我就只挑了一种传说中神奇的SAP算法学习。 首先引入几个新名词: 1、距离标号: 所谓距离标号 ,就是某个点到汇点的最少的弧的数量(即边权值为1时某个点到汇点的最短路径长度)。 设点i的标号为level[i],那么如果将满足level[i]=level[j]+1的弧(i,j)叫做允许弧 ,且增

KIJamesQi的博客 485

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

HDU1532 Drainage Ditches 网络流之SAP算法

HDU1532:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19000 Accepted Submission(s): 9058 Problem Description Every time it rain

雪的期许 962

HDU1532 Drainage Ditches 网络流--dinic算法 SAP算法

HDU1532:http://acm.hdu.edu.cn/showproblem.php?pid=1532Drainage DitchesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19000    Accepted Submissi...

雪的期许 1081

HDU1532 Drainage Ditches SAP+链式前向星

Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17065Accepted Submission(s): 8066 Problem Description Eve...

ddqb3235的博客 143

hdu1532最大流EK与SAP算法

EK是最朴素的最大流算法了,但效率比较慢,当然代码也比较清晰,思路去看LRJ的白书就行了。 但是由于网上大牛总结SAP基本上是解决最大流的最标准模板了,  网上大牛说基本没有什么最大流能卡SAP。   EK代码: #include #include #include using namespace std; const int N = 210; //小规模 不用考虑效率

amourjun的专栏 1177

POJ1273/HDU1532 最大流模板汇总

POJ1273/HDU1532算是最大流的模板题了。 最大流的算法有很多,我汇总了EK算法、SAP算法(邻接矩阵、邻接表)的模板,记录下来方便以后使用。但是这个原理emmmmm...我是真不清楚QAQ... 1.EK算法:(不常用) #include &lt;cstdio&gt; #include &lt;iostream&gt; #include &lt;queue&gt; #inclu...

A confused programmer 352

最大流【EK算法】HDU 1532模板题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 定义: 网络:网络是一个有向带权图,包含一个源点和一个汇点,没有反向平行边。 网络流:网络流即网上的流,是定义在网络边集E上的一个非负函数flow={flow(u,v)}, flow(u,v)是边上的流量。 可行流:满足以下两个性质的网络流flow称为可行流。 容量约束:每条边的实际流...

小康的博客 466

hdu 1532 Drainage Ditches (网络流两种方法)

hdu 1532 Drainage Ditches (网络流两种方法)

3808

HDU1532 Drainage Ditches(最大流)

学了一下午网络流,AC了这道模板题 勉强算是自己敲的,debug时参照了下模板,模板参照kuangbin大神 邻接表+isap算法 #include #include #define MAXN 210 #define MAXM 420 #define INF 0x3f3f3f3f struct node{ int to,next,cap; }edge[MAXM]; int

丶Hiroshi 587
上一篇: POJ3281 拆点 最大流 EK算法
下一篇: hdu 2883 最大流sap算法+离散化
Frozensmile
博客等级 码龄10年 16粉丝 77原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值