求最大流dinic算法模板
- //最短增广路,Dinic算法
- struct Edge
- {
- int from,to,cap,flow;
- };//弧度
- void AddEdge(int from,int to,int cap) //增弧
- {
- edges.push_back((Edge){from,to,cap,});
- edges.push_back((Edge){to,from,,});
- m=edges.size();
- G[from].push_back(m-);
- G[to].push_back(m-);
- }
- struct Dinic{
- int n,m,s,t;
- vector<Edge> edges;
- vector<int> G[maxn];
- bool vis[maxn];
- int d[maxn];
- int cur[maxn];
- bool Bfs() //构建分层网络
- {
- memset(vis,,sizeof(vis));
- queue<int> Q;
- Q.push(s);
- d[s]=;
- vis[s]=;
- while(!Q.empty())
- {
- int x=Q.front();
- Q.pop();
- for(int i=;i<G[x].size();i++)
- Edge& e=edges[G[x][i]];
- if(!vis[e.to]&&e.cap>e.flow)
- {
- vis[e.to]=;
- d[e.to]=d[x]+;
- Q.push(e.to);
- }
- }
- return vis[t];
- }
- };
- int DFS(int x,int a)//沿阻塞流增广
- {
- if(x==t||a==)
- return a;
- int flow=,f;
- for(int& i=cur[x];i<G[x].size();i++)
- {
- Edge& e=edges[G[x][i]];
- if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>)
- {
- e.flow+=f;
- edges[G[x][i]^].flow-=f;
- flow+=f;
- a-=f;
- if(a==)
- break;
- }
- }
- return flow;
- }
- int Maxflow(int s,int t)
- {
- this->s=;
- this->t=t;
- int flow=;
- while(BFS())
- {
- memset(cur,,sizeof(cur));
- flow+=DFS(s,inf);
- }
- return flow;
- }
求最大流dinic算法模板的更多相关文章
- POJ 1815 - Friendship - [拆点最大流求最小点割集][暴力枚举求升序割点] - [Dinic算法模板 - 邻接矩阵型]
妖怪题目,做到现在:2017/8/19 - 1:41…… 不过想想还是值得的,至少邻接矩阵型的Dinic算法模板get√ 题目链接:http://poj.org/problem?id=1815 Tim ...
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- poj 1273最大流dinic算法模板
#include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...
- 最大流Dinic算法模板(pascal)
program rrr(input,output); const inf=; type pointer=^nodetype; nodetype=record t,c:longint; next,rev ...
- HDU1532最大流 Edmonds-Karp,Dinic算法 模板
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- hdu 2435 dinic算法模板+最小割性质
#include<stdio.h> #include<queue> #include<string.h> using namespace std; #define ...
- 网络流之最大流Dinic算法模版
/* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
随机推荐
- gitlab4.0_安装
一,安装环境 OS:redhat7.4 二,安装依赖包 yum -y groupinstall 'Development Tools' ===>待验证 yum -y install pytho ...
- sudo安装某一文件报错:E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E: 无法锁定管理目录(/var/lib/dpkg/),是否有其他进程正占用它?
报错原因:资源被占用 解决方法: sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock
- <<Natural Language Inference over Interaction Space >> 句子匹配
模型结构 code :https://github.com/YichenGong/Densely-Interactive-Inference-Network 首先是模型图: Embedding Lay ...
- sitecore系统教程之内容创作入门
在Sitecore中,有两种编辑工具,您可以在其中创建和编辑网站上的内容: 内容编辑器 - 专为熟悉Sitecore及其包含的功能的经验丰富的内容作者而设计的应用程序. 体验编辑器 - 一种直观的编辑 ...
- Python - 2. Built-in Collection Data Types
From: http://interactivepython.org/courselib/static/pythonds/Introduction/GettingStartedwithData.htm ...
- jQuery工具--$.each()和$.merge()
jQuery.each(object, [callback])或者jQuery(object).each([callback]) 概述 通用遍历方法,可用于遍历对象和数组. 不同于遍历 jQue ...
- sql 表中删除字段重复的行
Id Email UserName1 Taiseer.Joudeh@hotmail.com TaiseerJoudeh2 Hasan.Ahmad@mymail.com ...
- sqoop使用经验总结及问题汇总
问题导读1.导入数据到HDFS,需要注意什么?2.在测试sqoop语句的时候,如何限制记录数量?3.sqoop导入时什么情况下会多导入一条数据? 一.sqoop 导入数据到HDFS注意事项 分割符的方 ...
- Vue + vant-UI 打造移动商城
- Linux基础命令---ifdown、ifup
ifup ifup指令用来启动网络接口设备,设备必须是定义在“/etc/sysconfig/network-scripts/ifcfg-ethX”或者“/etc/sysconfig/network”的 ...