hdu 3549 Flow Problem 基本网络流。
2011-08-08 09:30
141 查看
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <deque> using namespace std; int cap[100][100]; int a[100]; int flow[100][100]; int path[1010]; int N,M; const int inf = 0x7f7f7f7f; int f; void BFS( ) { int i, j, k, t, u, v; f = 0; memset(flow, 0, sizeof(flow)); for (; ; ) { memset(a, 0, sizeof(a)); memset(path, 0, sizeof(path)); deque<int>q; a[1] = inf; q.push_back(1); while (!q.empty( )) { t = q.front( ); q.pop_front( ); for (i = 0; i <= N; i++) if (!a[i] && flow[t][i] < cap[t][i] ) { path[i] = t; a[i] = min(a[t], cap[t][i] - flow[t][i]); q.push_back(i); } } if (a == 0) break; for (u = N; u != 1; u = path[u]) { flow[path[u]][u] += a ; flow[u][path[u]] -= a ; } f += a ; } printf("%d\n",f); } int main( ) { int T, l = 0, i, b, c, d; scanf("%d", &T); while (T--) { l++; scanf("%d%d", &N, &M); memset(cap, 0, sizeof(cap)); for (i = 0; i < M; i++) { scanf("%d%d%d", &d, &b, &c); cap[d][b] += c; } printf("Case %d: ",l); BFS( ); } return 0; }
相关文章推荐
- Island Transport HDU - 4280 (无向图形网络流)
- 网络流(最大流) HDU 1565 方格取数(1) HDU 1569 方格取数(2)
- hdu 1565 方格取数(1) (网络流/状压dp)
- 网络流 (费用流+拆边)——Transportation ( HDU 3667 )
- hdu-3416-Marriage Match IV-(求最小割)-网络流模板
- 网络流 ( 最小费用最大流 )——Going Home ( HDU 1533 )
- HDU 3452 Bonsai(网络流之最小割)
- HDU_3998_Sequence(最长上升子序列 + 网络流)
- 网络流改进SAP算法模版、HDU 1532 Drainage Ditches(解题报告)
- hdu 1086 很基本的计算几何
- 二分图带权最大独立集 网络流解决 hdu 1569
- HDU 4971 A simple brute force(网络流)
- HDU ~ 3416 ~ Marriage Match IV (最短路Dijkstra + 网络流Dinic)
- HDU--1251 -- 统计难题 [字典树基本应用] [用数组事先分配空间以节约时间]
- HDU 4975 A simple Gaussian elimination problem 网络流
- 网络流 二分图 基本习题
- HDU 4289 Control 网络流
- HDU 2435 There is a war (网络流-最小割)
- 【hdu 4497】GCD and LCM 【算术基本定理】
- 【网络流】 HDU 4183 Pahom on Water 拆点