POJ 1273 Drainage Ditches (最大流)
来源:互联网 发布:高中生很敏感知乎 编辑:程序博客网 时间:2024/05/14 18:35
题意
求一个边小于200点小于200的图的最大流。
思路
因为这里点比较少,直接用Edmonds_Karp(BFS)求就可以了,复杂度为
Ford-Fulkerson(DFS)的增广路次数为C,复杂度为O(E*C),不适用于这题。
代码
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define LL long long#define Lowbit(x) ((x)&(-x))#define lson l, mid, rt << 1#define rson mid + 1, r, rt << 1|1#define MP(a, b) make_pair(a, b)const int INF = 0x3f3f3f3f;const int Mod = 1000000007;const int maxn = 1e5 + 10;const double eps = 1e-8;const double PI = acos(-1.0);typedef pair<int, int> pii;int n, m;int start, ed;int g[220][220];int path[220], flow[220];int bfs(){ queue<int> q; memset(path, -1, sizeof(path)); path[start] = 0; flow[start] = INF; //源点有很多边相连 q.push(start); while (!q.empty()) { int t = q.front(); q.pop(); if (t == ed) break; for (int i = 1; i <= m; i++) { if (i != start && path[i] == -1 && g[t][i]) { flow[i] = min(flow[t], g[t][i]); q.push(i); path[i] = t; } } } if (path[ed] == -1) return -1; return flow[m];}int Edmonds_Karp(){ int max_flow = 0, step = 0, now, pre; while ((step = bfs()) != -1) { max_flow += step; now = ed; while (now != start) { pre = path[now]; g[pre][now] -= step; //更新正向边流量 g[now][pre] += step; //添加反向弧 now = pre; } } return max_flow;}int main(){ //freopen("H:\\in.txt","r",stdin); //freopen("H:\\out.txt","w",stdout); while (scanf("%d%d", &n, &m) != EOF) { memset(g, 0, sizeof(g)); for (int i = 0; i < n; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); g[u][v] += w; } start = 1, ed = m; printf("%d\n", Edmonds_Karp()); } return 0;}
0 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
- android 程序中取消标题栏
- AmBinaryEditor(AndroidManifest二进制修改工具介绍)
- HibernateTemplate的一些常用方法总结《转》
- mysql limit 优化
- CodeForces 659 C. Tanya and Toys
- POJ 1273 Drainage Ditches (最大流)
- studio快捷键
- 最短路径问题的相关算法
- Codeforces #3 A Shortest path of the king
- 指数函数方法
- JSP标签实现分页功能(ORM-mybatis)
- 复制构造函数的不同调用
- js中关于IE与DOM对浏览器的兼容性
- redigo的redis.Pool 配置参数调优