当前位置: 首页 > 网络知识

【模板】网络最大流

时间:2026-01-29 09:27:51

——果断附isap代码

1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 5 using std::min; 6 7 const int maxn = 200001; 8 9 int n, m, cnt, maxflow, s, t;//s为起点,t为终点 10 int head[maxn], next[maxn], to[maxn], val[maxn], gap[maxn], dis[maxn];//gap记录当前有多少点标号(层号)为k 11 12 inline void add(int x, int y, int z) 13 19 20 inline int dfs(int u, int flow) 21 32 if(!gap[dis[u]]) dis[s] = n; 33 ++gap[++dis[u]]; 34 return flow ret; 35 } 36 37 int main() 38 48 for(gap[s] = n; dis[s] < n;) maxflow += dfs(s, 1e9); 49 printf("%d", maxflow); 50 return 0; 51 }
Isap

其实我还没搞懂,但是感觉代码量好少!

然而——草,垃圾dfs,好多题都被卡,TM不用了!

但是迭代版的isap好像代码量多的一匹,所以我还是学Dinic吧,嗯,就这样。

Dinic代码,有当前弧优化。

1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 5 using namespace std; 6 7 int n, m, cnt, ans; 8 int head[10001], to[200001], val[200001], next[200001], dis[10001], cur[10001]; 9 10 void add(int x, int y, int z) 11 17 18 int dfs(int u, int t, int maxflow) 19 34 } 35 return ret; 36 } 37 38 bool bfs(int s, int t) 39 58 } 59 } 60 return 0; 61 } 62 int main() 64 74 //dinic 75 while(bfs(s, t)) 76 80 printf("%d", ans); 81 return 0; 82 }
Dinic



上一篇:【模板】Dijkstra的heap优化
下一篇:[HAOI2006]受欢迎的牛(tarjan缩点)
模板 最大流
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素