POJ 1273 Drainage Ditches 最大流
来源:互联网 发布:悟道红包软件 编辑:程序博客网 时间:2024/05/20 11:31
http://poj.org/problem?id=1273
题目大意:
给你N条路径(有重边),和M个点,求以1为源点,M为汇点的最大流。
思路:
第一题最大流问题,直接用Edmonds-Karp算法即可
#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;const int MAXN = 1<<8;int map[MAXN][MAXN];int flow[MAXN];int pre[MAXN];int n, m;int bfs(int s,int t){memset(pre, -1, sizeof(pre));queue<int> q;q.push(s);pre[s] = 0;flow[s] = 0x3ffffff;while (!q.empty()){int cur = q.front();q.pop();for (int i = 1; i <= m; i++) {if (map[cur][i] > 0 && pre[i] == -1){flow[i] = min(flow[cur],map[cur][i]);pre[i] = cur;q.push(i);}}}return pre[t] == -1 ? -1 : flow[t];}int maxFlow(int s,int t){int ans = 0;int curFlow=0;while ((curFlow=bfs(s,t)) !=-1){int cur = t;while (cur != s){map[pre[cur]][cur] -= curFlow;map[cur][pre[cur]] += curFlow;cur = pre[cur];}ans += curFlow;}return ans;}int main(){while (~scanf("%d%d", &n, &m)){memset(map, 0, sizeof(map));for (int i = 0; i < n; i++){int from, to, val;scanf("%d%d%d", &from, &to, &val);map[from][to] += val;}printf("%d\n", maxFlow(1,m));}}
2 0
- poj 1273 Drainage Ditches 网络最大流
- 【最大流】北大 poj 1273 Drainage Ditches
- POJ-1273 Drainage Ditches【最大流】
- poj 1273 Drainage Ditches--最大流--Dinic
- poj 1273Drainage Ditches 最大流
- poj 1273 Drainage Ditches--最大流--sap
- poj 1273 Drainage Ditches---maxflow最大流
- poj - 1273 - Drainage Ditches(最大流)
- poj 1273 Drainage Ditches(最大流)
- poj-1273 Drainage Ditches 最大流
- POJ 1273 Drainage Ditches 最大流
- poj 1273 Drainage Ditches (最大流Dinic)
- POJ 1273 Drainage Ditches 最大流
- POJ 1273 Drainage Ditches(最大流)
- POJ 1273 Drainage Ditches 最大流 dinic
- POJ 1273 Drainage Ditches 最大流
- POJ 1273 Drainage Ditches (网络最大流)
- poj 1273 最大流 Drainage Ditches
- 【PAT 1055】The World's Richest 结构体排序&剪枝
- linux使用小技巧
- 面向对象的特征有哪些方面
- Toast
- 源文件与模块生成时的文件不同 [vs2008]
- POJ 1273 Drainage Ditches 最大流
- 仿微信/QQ 开发基于XMPP的iPhone/iOS聊天客户端(一)好友资料
- LeetCode 025 Reverse Nodes in k-Group
- R的package虽多,感觉跟C++的比,还是差太远
- String是最基本的数据类型吗
- wordcount程序执行记录
- Web
- 底层技术自警
- int 和 Integer 有什么区别