HDU 4280 Island Transport 网络流
来源:互联网 发布:java模块化开发思路 编辑:程序博客网 时间:2024/05/16 17:44
有N个岛屿,M条路线,每条路都连接两个岛屿,并且每条路都有一个最大承载人数,现在想知道从最西边的岛到最东面的岛最多能有多少人过去
可以看出是最大流的问题,而且源点汇点也都给出了,可以用dinic解决
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <queue>#define rep(i, j, k) for(int i = j; i <= k; i++)#define maxn 100009#define inf 0x7fffffffusing namespace std;int s, t;int n, m, to[maxn * 3], head[maxn], done[maxn], d[maxn], tot, flow[3 * maxn], Next[3 * maxn];int cur[maxn];void add (int u, int v, int w){ to[++tot] = v; Next[tot] = head[u]; flow[tot] = w; head[u] = tot;}bool bfs (){ memset (done, 0, sizeof (done)); done[s] = 1; d[s] = 1; queue <int> q; q.push (s); while (!q.empty ()) { int now = q.front (); q.pop (); for (int i = head[now]; i; i = Next[i]) if (!done[to[i]] && flow[i] > 0) { d[to[i]] = d[now] + 1; done[to[i]] = 1; q.push (to[i]); } } return done[t];}int dfs (int x, int a){ if (x == t || a == 0) return a; int ret = 0, f; for (int &i = cur[x]; i; i = Next[i]) if (d[to[i]] == d[x] + 1 && flow[i] > 0 && (f = dfs (to[i], min (flow[i], a))) > 0) { flow[i] -= f; flow[i ^ 1] += f; a -= f; ret += f; if (!a) break; } return ret;}int MaxFlow (){ int ret = 0; while (bfs ()) { rep (i, 1, n) cur[i] = head[i]; ret += dfs (s, inf); } return ret;}int main (){ int ti; cin >> ti; while (ti--) { int u, v, w, Min = inf, Max = -inf; memset (head, 0, sizeof (head)); tot = 1; cin >> n >> m; rep (i, 1, n) { scanf ("%d%d", &u, &v); if (u < Min) Min = u, s = i; if (u > Max) Max = u, t = i; } rep (i, 1, m) scanf ("%d%d%d", &u, &v, &w), add (u, v, w), add (v, u, w); cout << MaxFlow () << endl; } return 0;}
0 0
- HDU 4280 Island Transport(网络流)
- HDU 4280 Island Transport(网络流)
- HDU 4280 Island Transport 网络流
- hdu 4280 Island Transport 【网络流+优化】
- HDU 4280 Island Transport 网络流
- HDU 4280 Island Transport (网络流)
- HDU 4280 Island Transport 网络流sap
- HDU 4280 Island Transport 网络流
- HDU 4280Island Transport(网络流之最大流)
- HDU 4280 Island Transport (网络流 sap)
- HDU 4280 Island Transport(网络流,SAP)
- hdu 4280 Island Transport 【图论-网络流-ISAP+栈优化】
- HDU 4280 Island Transport 网络流裸题
- hdu 4280 Island Transport
- HDU 4280 Island Transport
- HDU - 4280 Island Transport
- hdu 4280 Island Transport
- [Hdu 4280]Island Transport
- light oj 1189 - Sum of Factorials (阶乘+贪心)
- JAVA进阶 面向对象程序设计——第4章 继承与多态【不同访问属性使子类在使用这些成员时不同】
- 2016.9.11学生管理系统 1.0完成
- javascript中原型模式创建对象特点分析
- Unity3D 资源管理 -- 基本概念
- HDU 4280 Island Transport 网络流
- 【OpenCV】双目测距(双目标定、双目校正和立体匹配)
- 从尾到头打印链表
- c++中struct的使用方法
- Retrofit+Rxjava的封装
- Java学习提要——日期处理类
- graphx与完全图
- 基于深度学习的人脸识别系统系列(Caffe+OpenCV+Dlib)——【五】设计人脸识别的注册类
- 算法学习笔记 - 冒泡排序