网络流--最大流ek模板
2024-08-23 23:48:46
标准大白书式模板,代码简单但由于效率并不高,所以并不常用,就是这样
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const int maxm=+;
const int INF=0x3f3f3f3f; struct edge{
int from,to,c,f;
edge(int a,int b,int m,int n):from(a),to(b),c(m),f(n){}
}; struct ek{
int n,m;
vector<edge>e;
vector<int>g[maxm];
int a[maxm];
int p[maxm]; void init(int n){
for(int i=;i<n+;i++)g[i].clear();
e.clear();
} void add(int from,int to,int c){
e.push_back(edge(from,to,c,));
e.push_back(edge(to,from,,));
m=e.size();
g[from].push_back(m-);
g[to].push_back(m-);
} int mf(int s,int t){
int f=;
while(){
memset(a,,sizeof(a));
queue<int>q;
q.push(s);
a[s]=INF;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<g[u].size();i++){
edge tmp=e[g[u][i]];
if(!a[tmp.to]&&tmp.c>tmp.f){
p[tmp.to]=g[u][i];
a[tmp.to]=min(a[u],tmp.c-tmp.f);
q.push(tmp.to);
}
}
if(a[t])break;
}
if(!a[t])break;
for(int i=t;i!=s;i=e[p[i]].from){
e[p[i]].f+=a[t];
e[p[i]^].f-=a[t]; }
f+=a[t];
}
return f;
}
};
最新文章
- python——协程
- Android FM 模块学习之四 源码解析(1)
- c sharp学习 问题记录
- (剑指Offer)面试题21:包含min函数的栈
- Chapter 8. Classes
- 九度OJ 1361 翻转单词顺序
- The Tips of Success(成功的建议)
- 修改一个Label上字体的大小(富文本)
- Python线程的常见的lock
- java之Spring(IOC)装配Bean(手动装配、自动装配、注解装配)
- Android Bundle详解
- WPF中在MVVM模式下,后台绑定ListCollectionView事件触发问题
- Spring Boot——Linux 启动方式
- 【Core】在mvc使用EF
- React-本地状态(state)
- kdTree相关原理及c++实现
- 【iOS】TableView的footerView不随cell滚动而停留在tableView底部的问题
- 三、Shiro授权开发
- 20155327 2016-2017-2 《Java程序设计》第一周学习总结
- JavaScript 核心