【模板】dinic初体验

网络流Dinic算法详解及模板 在程序里,p表示找到的增广路径,p.top为路径中的最后一个顶点。一开始,p中只有源点。 整个While循环分为2个操作。如果p的最后一个顶点为汇点,也就是说找到了增广路,那么对p增广,注意到增广后一定有一条或多条p中的边被删除了。这时,我们使增广路径后退至p中从源点可到达的最后一个顶点。 如果p的最后一个顶点不为汇点,那么观察最后那个的顶点u 。若在层次图中存在从u连出的一条边,比如(u,v),我们就将顶点v放入路径p中,继续dfs遍历;否则,点u对之后的dfs遍历就没有用了,我们将点u以及层次图中连到u 阅读详情

题目描述

觊觎已久的dinic网络流~
果然还是晓犇讲代码神啊~~~@Starria
第一个板子就在这里开荒留下足迹吧w~

#include<cstdio>
#include<algorithm>
#define N 1100
#define INF 1000000000
using namespace std;
struct node{
    long long to,len,nxt;
}table[N<<1];
long long tot=2,head[N],queue[N],l,r,n,m,S,T,ans=0;
void add(long long x,long long y,long long z){
    table[tot].len=z,table[tot].to=y,table[tot].nxt=head[x],head[x]=tot++;
    table[tot].len=0,table[tot].to=x,table[tot].nxt=head[y],head[y]=tot++;
    return;
}
long long vis[N];
bool bfs(){
    l=r=0;
    for(long long i=0;i<=n;i++){
        vis[i]=0;
    }
    vis[S]=1;
    queue[r++]=S;
    while(l!=r){
        long long t=queue[l++];
        for(long long i=head[t];i;i=table[i].nxt){
            if((!vis[table[i].to])&&table[i].len){
                vis[table[i].to]=vis[t]+1;
                queue[r++]=table[i].to;
            }
        }
    }
    if(vis[T]){
        return true;
    }
    return false;
}
long long dfs(long long x,long long val){
    if(x==T){
        return val;
    }
    long long res=0;
    for(long long i=head[x];i;i=table[i].nxt){
        if(table[i].len!=0&&vis[table[i].to]==vis[x]+1){
            long long chg=dfs(table[i].to,min(val,table[i].len));
            table[i].len-=chg,table[i^1].len+=chg,val-=chg,res+=chg;
        }
    }
    return res;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&m,&S,&T);
    for(long long i=0;i<m;i++){
        long long x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        add(x,y,z);
    }
    while(bfs()){ans+=dfs(S,INF);};
    printf("%lld\n",ans);
    return 0;
}
A2B音频总线在智能座舱中的应用 车载A2B链路音频是智能座舱的核心功能,涵盖车载音响、语音识别、e-Call、消噪及回声消除等应用,随着汽车智能网联化的发展,对音频的开发要求也越来越高,需要加入更先进、功能丰富的信息娱乐功能以满足消费者的用户体验。但传统的模拟并行音频信号传输方式,难以在功能增加与整车轻量化(线缆的重量及成本减少)之间取得均衡。这时候就需要A2B音频总线了。A2B音频总线用于连接车辆中的音频设备,如麦克风(MIC)、功放(AMP)、多媒体主机(Head Unit)和T-BOX等。通过一条低成本的非屏蔽双绞线UTP,进行跨距 阅读详情

相关推荐

静态分析工具COBOT与Testbed对比

Testbed为规则检查工具的代表,市场占有量非常大,但随着时间的推移,大家从规则匹配转向了用静态分析工具检查Bug,所以规则检查型工具占有量比开始时候已经减少,但仍有一些比较落后的单位还在继续采购此类工具。3、通过对开源工程的测试,进行误漏报率的对比,发现COBOT(库博)的误漏报率相比Testbed较低,因COBOT主打国内市场,在众多军工单位进行大量试用及使用,吸取了众多单位的意见和建议,更加符合国内军工单位的使用习惯及测试要求。4、此外库博在功能上还可以进行计划任务,检测队列,检测并发的功能支持。

chengoodflower的博客 2055

蒟蒻名曰Starria-博客两周年纪念

「——这是回忆录吗?为什么不写在新博客里?」 「——我有一定要发在这里的理由。」

蒟蒻名曰Starria 1721

深入解析STM32H743双精度FPU:从配置误区到三角函数加速技巧

本文深入解析STM32H743双精度FPU的配置与优化技巧,涵盖常见误区、三角函数加速及飞控系统应用。通过实测数据展示如何利用FPU提升数学运算效率,特别适合工业控制、无人机飞控等高精度实时应用场景。

weixin_29190651的博客 640

wc2018冲刺期总结

写给自己。 写给以后可能会和我有相同经历的oier。 prev: 「noip2017冲刺期总结」 时间:noip2017后~wc2018前(2017.11~2018.2) 这次感觉写了一堆无关紧要的东西…当回忆录看吧(雾 //整篇都是半夜写的,可能之后要斟酌一下词句改一下? (续)十一月,等到了noip的正式分,发现比民间数据高真是愉悦,然而周围很多oier惨挂,包括一致认为...

蒟蒻名曰Starria 1664

【AI智能体】最强AI编程利器 Claude Code 从部署到项目实战详解

最强AI编程利器 Claude Code 从部署到项目实战详解

congge 4511

SQL注入详解

SQL注入(SQL Injection)是一种常见的Web安全漏洞,主要形成的原因是在数据交互中,前端的数据传入到后台处理时,没有做严格的判断,导致其传入的“数据”拼接到SQL语句中后,被当作SQL语句的一部分执行。 从而导致数据库受损(被脱库、被删除、甚至整个服务器权限陷)。 即:注入产生的原因是后台服务器接收相关参数未经过滤直接带入数据库查询...

渗透之路,攻防之间皆学问 26万+

noip2017冲刺期总结

//第一次写总结,感觉这种东西好像不是这么写的 写给自己。 写给以后可能会和我有相同经历的oier。 时间:noi2017后~noip2017前(2017.7~2017.11) 这一段的主线基本就是寻找文化课和oi的平衡了。 七月,中考结束,恢复代码力,认全了现在机房里的人,发现自己其实很弱,而大家都变强了,noi同步赛打了45还是55,听说alone_wolf/ljss/ah...

蒟蒻名曰Starria 1232

YOLOv12优化:原创自研 | 带有注意力机制的隐藏状态混合器的状态空间(HSM-SSD),实现暴力涨点 | CVPR2025 EfficientViM

可以将 带有注意力机制的隐藏状态混合器的状态空间(HSM-SSD)中的注意力机制换成专栏其他注意力机制 ,那么你就能实现独一无二的原创。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 664

JLOI2017——相逢是问候,离别是祝愿

又是一年春花烂漫省选季,成绩公布,又有六省AB类省队尘埃落定 不过逼话还是少说,我也说不出来什么逼话,老老实实写写流水账吧

neither_nor 3582

[计算机头歌]爬虫进阶

【代码】爬虫进阶。

M_inherit的博客 921

AOSP 8.0.0编译中的ANDROID_DATA缺失问题解决方案

在AOSP编译过程中,环境变量和路径设置的正确性至关重要。遇到相关的错误时,检查并修正环境配置通常是解决问题的关键。希望本文提供的分析和解决方案能帮助你顺利编译AOSP。

m0_74337424的博客 397

uoj#347. 【WC2018】通道 //点分治×虚树

uoj#347. 【WC2018】通道 给出三棵n(≤10^5)个点的树,边有边权Li(≤10^12),求max1≤i,j≤n(dis1(i,j)+dis2(i,j)+dis3(i,j))。

蒟蒻名曰Starria 1006

【YOLO目标检测全栈实战】98 YOLO模型在低光照环境下的自适应增强策略

你有没有遇到过这种情况?深夜加班调试产线检测模型,车间灯光昏暗,摄像头采集的图片黑乎乎一片,YOLO模型直接“罢工”——漏检率飙升到40%以上。上个月我在一个汽车零部件质检项目里就栽了跟头:白天模型跑得飞起,mAP@0.5达到0.92,可一到夜班,同样的产线、同样的零件,mAP直接掉到0.63。客户拍着桌子问我:“你这模型怎么还分白天黑夜?”

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 284

dinic模板

dinic在思想上是对原图分层得到层次图,然后找到当前层次图下的得到极大流(阻塞流),不断重复这个过程直到不再有增广路为止; 将以前写的模板优化修改后的版本,增加了当前弧优化; 看过紫书上的版本后感觉那个写法性能应该更好,当前弧优化的作用更高,但实际跑下来(洛谷模板)还是之前的那个一次bfs对多次dfs的版本跑的快一些,因此这里暂时保留之前版本; #include<iostream> #include<queue> #include<cstring> #include.

gyp0205的博客 275

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

蓝牙模块HM-10手册

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

Dinic模板

hhhh赛前自己写了一个版本的模板,也不知道效率咋样,但是亲手写出来的意义不同!嗯! #include<bits/stdc++.h> using namespace std; #define INF (1e18) typedef long long ll; const ll maxn=205,maxm=50205; ll n,m,S,T,sum,cnt; ll l[maxm]...

Mr_Alice的博客 363

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Dinic【模板】

struct Edge{ int next, to; Edge(){}; Edge(int next, int to): next(next), to(to){}; }edge[maxm*2]; int head[maxn], W[maxn], cnt; void add(int u, int v, int w){ edge[++cnt] = Edge(head[u], v); hea...

Wtothey_的博客 207

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Dinic算法JAVA模板

笔者学习来源:https://www.cnblogs.com/SYCstudio/p/7260613.html 在这个信息爆炸的时代,本着达者为师的态度在大佬的博客中取的Dinic模板之经。 为在下以后愉快的玩耍板子,写写学习经验总坛。 Dinic算法 相较于EK算法,dinic多了一个分层的概念; dinic做法,首先用bfs把图分层,分深度,即每个节点都有他...

qq_43389392的博客 778

网络流Dinic算法 +模板

网络流模板Dinic算法模板题P3376 【模板】网络最大流(Dinic模板)Island Transport HDU - 4280ISAP模板SAP模板 Dinic算法 dinic算法流程 先用bfs分层,搜出当前网络(容量网络或残量网络)中每个点的depth。判断条件是:如果当前点未被访问且当前的最大流量不为0,则标记它的深度并入队 然后用dfs搜索增广路,当前流量为curflow,表示流到当前点u的最大流量。如果为0,或者已经走到汇点t,则返回。否则就搜索 比当前点u深度多1的点v,并且(u,v)这

cheng__yu_的博客 567

dinic算法模板

#include #include #include #include #include #include #include #define MAXN #define starNode 0 #define finishNode #define INF 0x3f3f3f3f #define ll long long #define re return #define getLen(na...

突破吧!次元壁 737

dinic 模板

自己整理,仅做模板保存。 cur【】数组是当前弧优化的辅助数组。 当前弧优化是dinic算法中十分重要的优化。cur【】数组的使用方法即首先将head【】数组复制一遍。在dfs中再改变当前榨取到哪一条边。每次榨取,该边所有流量必定被榨干,下一次搜索,直接从这条边开始就好。 #include<bits/stdc++.h> #define ll long long using namesp...

我不想打铁 373

ACM 最大流 dinic 模板

最大流的应用实在是太广泛了 几个比较有用的定理: 最大流=最小割 二分图最大匹配=二分图最小点覆盖(最大流) 二分图的匹配直接用最大流好了。 下面是个很喜欢的dinic模板,顺便用这个版过掉POJ3041 #include using namespace std; const int maxn=150000; const int maxm=2000000; const int

z3635363的专栏 732

网络流模板 dinic

1 #include<iostream> 2 #include<cstring> 3 #include<queue> 4 using namespace std; 5 6 const int maxn=1e5+10; 7 const int maxe=4e5+10; 8 const int inf=0x3f3f3f3f; ...

weixin_30690833的博客 144

(模板) Dinic 最大流

代码 /* * DINIC 模板 * * BEGIN */ /* 需要的头文件 #include <string.h> #include <queue> #include <vector> using namespace std; */ #define MAXN 10000 // 结点最大数量 #define INF 0x7fffffff ty...

王成昊的博客 198

网络流Dinic算法模板(易理解)

网络流Dinic算法模板 #include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; const int maxn=2e5+10; int head[maxn],cnt; struct Edge{ int to,next,flow/*流量*/,cap/*最大流量*/; }edge[maxn]; void add_Edge(int u,int v,int cap){ //建图(包括反向路径) edge[cnt

weixin_48964494的博客 240
上一篇: 【BZOJ】T3240 矩阵游戏
下一篇: 【模板】exgcd初体验
coldhac
博客等级 码龄10年 4粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值