10330 - Power Transmission (最大流)
来源:互联网 发布:linux 编译python模块 编辑:程序博客网 时间:2024/05/18 03:37
Power Transmission
The Problem
DESA is taking a new project to transfer power. Power is generated by the newly established plant in Barisal. The main aim of this project is to transfer Power in Dhaka. As Dhaka is a megacity with almost 10 million people DESA wants to transfer maximum amount of power through the network. But as always occurs in case of power transmission it is tough to resist loss. So they want to use some regulators whose main aim are to divert power through several outlets without any loss.
Each such regulator has different capacity. It means if a regulator gets 100 unit power and it's capacity is 80 unit then remaining 20 unit power will be lost. Moreover each unidirectional link( Connectors among regulators) has a certain capacity. A link with capacity 20 unit cannot transfer power more than 20 unit. Each regulator can distribute the input power among the outgoing links so that no link capacity is overflown. DESA wants to know the maximum amount of power which can be transmitted throughout the network so that no power loss occurs. That is the job you have to do.
( Do not try to mix the above description with the real power transmission.)
The Input
The input will start with a postive integer N ( 1<=N<=100 ) indicates the number of regulators. The next few lines contain N positive integers indicating the capacity of each regulator from 1 to N. The next line contains another positive integer M which is the number of links available among the regulators. Following M lines contain 3 positive integers ( i j C) each. 'i' and 'j' is the regulator index ( 1<=i,j<=N) and C is the capacity of the link. Power can transfer from i'th regulator to j'th regulator. The next line contains another two positive integers B and D. B is the number of regulators which are the entry point of the network. Power generated in Barisal must enter in the network through these entry points. Simmilarly D is the number of regulators connected to Dhaka. These links are special and have infinite capacity. Next line will contain B+D integers each of which is an index of regulator. The first B integers are the index of regulators connected with Barisal. Regulators connected with Barisal are not connected with Dhaka.
Input is terminated by EOF.
The Output
For each test case show the maximum amount of power which can be transferred to Dhaka from Barisal. Use a seperate line for each test case.
Sample Input
410 20 30 4061 2 51 3 101 4 132 3 52 4 73 4 203 11 2 3 4250 10011 2 1001 11 2
Sample Output
3750
#include <stdio.h>#include <string.h>#include <queue>#define min(a,b) (a)<(b)?(a):(b)#define max(a,b) (a)>(b)?(a):(b)#define INF 0x3f3f3f3fusing namespace std;const int N = 205;int n, limit, m, A, B, V, sn, tn, line, g[N][N], f[N][N], a[N], p[N];queue<int>q;void init() { memset(g, 0, sizeof(g)); for (int i = 1; i <= n; i ++) {scanf("%d", &limit);g[i][i + n] = limit; } scanf("%d", &m); while (m --) {scanf("%d%d%d", &A, &B, &V);g[A + n][B] = V; } scanf("%d%d", &sn, &tn); for (int i = 0; i < sn; i ++) {scanf("%d", &line);g[0][line] = INF; } for (int i = 0; i < tn; i ++) {scanf("%d", &line);g[line + n][2 * n + 1] = INF; }}int solve(int s, int t) { init(); int ans = 0; memset(f, 0, sizeof(f)); while (1) {memset(a, 0, sizeof(a));a[s] = INF;q.push(s);while (!q.empty()) { int u = q.front(); q.pop(); for (int v = 1; v <= t; v ++) {if (!a[v] && g[u][v] > f[u][v]) { p[v] = u; q.push(v); a[v] = min(a[u], g[u][v] - f[u][v]);} }}if (!a[t]) break;for (int u = t; u != s; u = p[u]) { f[p[u]][u] += a[t]; f[u][p[u]] -= a[t];}ans += a[t]; } return ans;}int main() { while (~scanf("%d", &n)) {printf("%d\n", solve(0, 2 * n + 1)); } return 0;}
- 10330 - Power Transmission (最大流)
- UVa 10330 Power Transmission / 最大流EK
- UVA 10330 Power Transmission(网络最大流)
- UVA - 10330 Power Transmission 最大流问题
- Power Transmission - UVa 10330 最大流
- UVa 10330 - Power Transmission (最大流+拆点)
- UVa 10330 Power Transmission(最大流 + 拆点)
- UVA - 10330 Power Transmission (最大流+拆点)
- uva 10330 Power Transmission (最大流 + 拆点)
- LightOJ 1155Power Transmission 最大流
- UVa 10330 Power Transmission (最大流+多源多汇点+结点容量(拆点))
- UVa10330 Power Transmission (最大流,拆点)
- Ligthoj 1155--Power Transmission【最大流 && 拆点】
- uva 10330 - Power Transmission(网络流)
- uva 10330 Power Transmission (网络流)
- uva 10330 - Power Transmission
- 10330 - Power Transmission
- UVa:10330 Power Transmission
- 关于字节对齐的总结
- Cocos2d-x 寻路算法之一 距离优先
- Java多线程-线程的调度(守护线程)
- 文件夹病毒专杀简单实现
- 短信会话界面EditText,焦点获取直接弹出输入法的问题
- 10330 - Power Transmission (最大流)
- OpenCart之商品管理教程
- jQuery Sizzle选择器
- Android 动画之Interpolator插入器
- Why vendors can't sell OpenStack to enterprises
- Java 父类和子类对象销毁实例
- ubuntu用ssh挂载远程主机上的目录到本地
- 如何安装C/C++ GNU Scientific Library(GSL) for Windows
- UIViewContentModeScaleAspectFill图片放大