poj 1273 Drainage Ditches (第一道网络流~)
来源:互联网 发布:搜索东西的软件 编辑:程序博客网 时间:2024/06/06 00:22
网络流入门题,注意可能有重边。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;const int maxn = 210;int c[maxn][maxn], pre[maxn], f[maxn][maxn];int n, m, add;bool bfs(){ queue<int> Q; memset(pre, -1, sizeof(pre)); add = 1000000000; Q.push(1); pre[1] = 0; while (!Q.empty()) { int cur = Q.front(); Q.pop(); for (int i = 1; i <= m; ++i) { if (pre[i] == -1 && c[cur][i] > f[cur][i]) { pre[i] = cur; add = min(add, c[cur][i] - f[cur][i]); if (i == m) return true; Q.push(i); } } } return false;}int maxFlow(){ int ret = 0; while (bfs()) { ret += add; int p = m; while (pre[p] != 0) { f[pre[p]][p] += add; f[p][pre[p]] -= add; p = pre[p]; } } return ret;}int main(){ while (scanf("%d %d", &n, &m) != EOF) { memset(c, 0, sizeof(c)); memset(f, 0, sizeof(f)); int S, E, C; for (int i = 0; i < n; ++i) { scanf("%d %d %d", &S, &E, &C); c[S][E] += C; } printf("%d\n", maxFlow()); } return 0;}
- poj 1273 Drainage Ditches (第一道网络流~)
- POJ 1273 Drainage Ditches 我的第一道网络流——最大流问题
- POJ 1273 - Drainage Ditches (网络流)
- POJ 1273 Drainage Ditches (网络流)
- HDU-1532 Drainage Ditches,人生第一道网络流!
- poj 1273 Drainage Ditches 网络最大流
- poj 1273 Drainage Ditches--网络流
- 【网络流】poj 1273 Drainage Ditches
- 网络流poj(1273)Drainage Ditches
- POJ 1273 Drainage Ditches 【网络流】
- POJ 1273 Drainage Ditches 网络流模版
- POJ 1273 Drainage Ditches (网络最大流)
- POJ 1273 Drainage Ditches 网络流基础
- 【网络流】 POJ 1273 Drainage Ditches
- 网络流模板 POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches 经典网络流
- POJ 1273 Drainage Ditches 网络流算法 .
- 【POJ】1273 Drainage Ditches 网络最大流
- android 汉化
- firefox同步书签的插件xmarks
- 一个安装winXP系统很有用的链接
- Xcode4.2设置作者名称和公司名称
- NiRenderStep
- poj 1273 Drainage Ditches (第一道网络流~)
- 我的所有技术博客以及声明
- 飞鸽传书程序IT基础架构和应用的管理
- Tomcat 下二级域名如何共享Session
- 改变SQLServer2008设置开启远程连接
- 弹出窗口代码大全
- DrawCli代码中双缓冲,裁剪区技术以及坐标变换等技术分析
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)的一种解决方法
- Entity Framework菜鸟初飞【1】——Entity Data Model