poj1273 最大流模板 Edmond_karp算法
来源:互联网 发布:压缩包软件 编辑:程序博客网 时间:2024/06/07 16:21
Edmond_karp算法:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int maxn = 200 + 5;const int inf = 0x7f7f7f7f;int pre[maxn], c[maxn][maxn], flow[maxn];int ans;int bfs(int s, int t){ queue<int> q; memset(pre, -1, sizeof(pre)); memset(flow, 0, sizeof(flow)); q.push(s); flow[s] = inf; while(!q.empty()) { int u = q.front(); q.pop(); if (u == t) break; for (int i = 1; i <= t; i++) { if (!flow[i] && c[u][i] > 0) { pre[i] = u; q.push(i); flow[i] = min(flow[u], c[u][i]);//s-v路径上的最小残量 } } } if (pre[t] == -1) return -1; return 1;}int Edmond_karp(int s, int t){ int max_flow = 0; while (bfs(s, t) != -1)//寻找增广路径 { max_flow += flow[t]; int k = t; while (pre[k] != -1) { c[pre[k]][k] -= flow[t];//更新正向流量 c[k][pre[k]] += flow[t];//更新反向流量 k = pre[k]; } } return max_flow;}int main(){ //freopen("input.txt", "r", stdin); int n, m; while (cin >> n >> m) { memset(c, 0, sizeof(c));//初始化 for (int i = 0; i < n; i++) { int u, v, x; scanf("%d%d%d", &u, &v, &x); c[u][v] += x; } printf("%d\n", Edmond_karp(1, m)); } return 0;}
0 0
- poj1273 最大流模板 Edmond_karp算法
- poj1273及最大流Edmond karp算法模板
- [模板]最大流(Edmonds_Karp/Dinic算法(以poj1273为例
- 网络流最大流模板(poj1273)
- POJ1273 最大流模板题_Edmonds_Karp
- POJ1273 Drainage Ditches最大流模板
- 8.9 poj1273最大流 (Dinic模板练习)
- poj1273 Drainage Ditches (最大流模板)
- Poj1273最大流 裸题模板
- POJ1273 网络流-->最大流-->模板级别-->最大流常用算法总结
- poj1273 Drainage Ditches 最大流 dinic算法
- Dinic算法解决最大流问题poj1273
- 网络流Dinic算法模板 POJ1273
- POJ1273 最大流模板题 初学网络流~
- 【网络流之最大流】POJ1273-Drainage Ditche【模板题】
- POJ1273 Drainage Ditches(网络流最大流模板)
- POJ1273 Drainage Ditches 最大流模板题(dinic)
- 最大流的理解以及dinic模板 poj1273
- 1-2、自定义Partitioner代码
- 虚拟机与docker
- 【ACM】华为oj--合法ip
- iOS项目开发实战——学会使用TableView列表控件(一)
- 在Word中用快捷键转换英文字母大小写
- poj1273 最大流模板 Edmond_karp算法
- ERROR:column "datconfig " does not exist character
- 数据结构学习笔记之二叉树
- C++学习——vector
- Double Shortest Paths(费用流)2014年省赛D题
- Android带CheckBox的ListView,全选,CheckBox和ListView事件分离
- C++ STL vector(向量容器)的使用(附完整程序代码)
- netty5学习笔记-内存泄露检测
- 二叉树的那些事