10330 - Power Transmission (最大流)

原创 2013年12月02日 14:29:14

 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

4
10 20 30 40
6
1 2 5
1 3 10
1 4 13
2 3 5
2 4 7
3 4 20
3 1
1 2 3 4
2
50 100
1
1 2 100
1 1
1 2

Sample Output

37
50
题意:给定n个输送点,有流量上限,然后从一个源点要输送到汇点,求最多输出多少流量
思路:最大流 拆点。
代码:
#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 0x3f3f3f3f
using 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;
}


UVa 10330 Power Transmission (最大流+多源多汇点+结点容量(拆点))

题意:一张有向图由n个点构成,每个点都有一个容量限制,然后给出多个源点和多个汇点。 #include #include #include #include #include #include #in...
  • Slow_Wakler
  • Slow_Wakler
  • 2015年08月07日 16:24
  • 778

关于transmission下载速度提升的小建议

由于项目中you
  • u012427276
  • u012427276
  • 2014年06月07日 21:53
  • 4140

Ubuntu下关于Transmission daemon的安装与配置

原文链接:http://cliang.info/?p=19 1. Transmission介绍 Transmission是一个强大的BitTorrent开源客户端,实现了BT协议中描述的大...
  • stripe3385
  • stripe3385
  • 2016年01月08日 15:02
  • 8582

UVA 10330 Power Transmission 网络流 拆点+多源点多汇点

题意:一张有向图由n个点构成,每个点都有一个容量限制,然后给出多个源点和多个汇点。 经典的模型,拆点,构造超级源点和超级汇点,然后用最大流算法即可。 注意要小心构造图。 代码: /* * A...
  • hcbbt
  • hcbbt
  • 2013年12月06日 16:53
  • 1776

transmission远程调用协议

本文档讲述了一个远程调用transmission会话的协议。This document describes a protocol for interacting with Transmission s...
  • hyq776141352
  • hyq776141352
  • 2017年04月08日 14:50
  • 303

在小米路由器mini上安装Transmission挂BT/PT

小米路由器mini虽宣称是一款智能路由器,可是其支持的插件实在太少所幸小米路由mini使用的是OpenWrt系统,经过研究发现,基于OpenWRT的小米路由器系统是支持OpenWRT源中的ipk插件包...
  • xiaopang1122
  • xiaopang1122
  • 2016年01月26日 13:57
  • 3539

transmission-daemon已完成列表位置

下载完成的种子文件是有一个列表的,每次软件开启都会搜索这个列表去寻找本地文件开始做种,那么请问这个列表在哪里。我们找到了这个位置。...
  • px_528
  • px_528
  • 2017年04月28日 17:12
  • 536

值得一试的四款Linux Torrent客户端软件

original url: http://www.linuxidc.com/Linux/2016-08/134519.htm 我最近由Ubuntu换成了Arch Linux,正...
  • junmuzi
  • junmuzi
  • 2017年02月18日 19:37
  • 1945

见过的最清晰的讲解最大流思路的文章

原创路径:http://www.wutianqi.com/?p=3107 Edmond Karp算法的大概思想: 反复寻找源点s到汇点t之间的增广路径,若有,找出增广路径上每一段[容量-流量]...
  • xiaoxin_ling
  • xiaoxin_ling
  • 2014年02月26日 11:22
  • 4187

Mac OS X 设置指南

由于公司的IOS离职,侥幸获得其Mac Pro的使用权,因此特地总结了下小白使用Mac OS X的初始配置。 1、系统首选项(system preeferences) 我拿到电脑确...
  • wh211212
  • wh211212
  • 2017年02月20日 23:44
  • 657
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:10330 - Power Transmission (最大流)
举报原因:
原因补充:

(最多只允许输入30个字)