POJ 1459 Power Network (maximum stream base multi-source point Edmonds_karp algorithm)

Source: Internet
Author: User


Power Network
Time Limit: 2000MS Memory Limit: 32768K
Total Submissions: 24056 Accepted: 12564

Description

A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node U is supplied with an amount s (U) >= 0 of the power, may produce an amount 0 <= P (u) <= pmax (U) of power, May consume a amount 0 <= C (u) <= min (S (u), Cmax (U)) of power, and may deliver an amount D (u) =s (u) +p (U)-C (U) of Powe R. The following restrictions Apply:c (U) =0 for any power station, p (U) =0 for any consumer, and P (u) =c (u) =0 for any Dispat Cher. There is at most one Power transport line (U,V) from a node u to a node V in the net; It transports an amount 0 <= L (u,v) <= Lmax (u,v) of the Power delivered by U v. Let Con=σuc (U) is the power consumed in the net. The problem is to compute the maximum value of Con.

An example was in Figure 1. The label X/y of power station U shows that P (u) =x and Pmax (U) =y. The label x/y of consumer U shows that C (U) =x and Cmax (U) =y. The label X/y of Power Transport Line (U,V) shows that L (u,v) =x and Lmax (u,v) =y. The power consumed is con=6. Notice that there is other possible states of the network but the value of Con cannot exceed 6.

Input

There is several data sets in the input. Each data set encodes a power network. It starts with four integers:0 <= n <= (nodes), 0 <= NP <= N (power stations), 0 <= NC <= N (consum ERS), and 0 <= m <= n^2 (Power transport Lines). Follow M data triplets (u,v) z, where u and v are node identifiers (starting from 0) and 0 <= z <= of Lmax (U,V). Follow NP doublets (U) z, where U is the identifier of a power station and 0 <= Z <= 10000 is the value of Pmax (U). The data set ends with NC doublets (u) z, where u are the identifier of a consumer and 0 <= Z <= 10000 is the value of Cmax (U). All input numbers is integers. Except the (u,v) z Triplets and the (U) z doublets, which do not contain white spaces, white spaces can occur freely in Inpu T. Input data terminate with an end of file and is correct.

Output

for each data set from the input, the program prints on the standard output the maximum amount of power that can is co Nsumed in the corresponding network. Each result have an integral value and are printed from the beginning of a separate line.

Sample Input

2 1 1 2 (0,1) (1,0) ten (0) (1) 207 2 3 (0,0) 1 (0,1) 2 (0,2) 5 (1,0) 1 (8) (2,3) 1 (2,4) 7 (3,5) 2 (3,6) 5 (4,2)         7 (4,3 ) 5 (4,5) 1 (6,0) 5         (0) 5 (1) 2 (3) 2 (4) 1 (5) 4

Sample Output

156

Hint

The sample input contains the data sets. The first data set encodes a network with 2 nodes, power station 0 with Pmax (0) =15 and Consumer 1 with Cmax (1) =20, and 2 p Ower Transport lines with Lmax (0,1) =20 and Lmax (1,0) =10. The maximum value of Con is 15. The second data set encodes the network from Figure 1.

Source

Southeastern Europe 2003

Title Link: poj.org/problem?id=1459

Main topic: There are N nodes, NP power station, NC users, M transmission road, give M transmission road and the maximum power on the road, and then give the NP power station location and maximum power generation, NC user position and maximum electricity consumption, to find the power grid can be consumed by the maximum power

Topic Analysis: Because it is a multi-source point multi-Meeting point, so we want to set a total source point and a confluence point, so that the total source point 0 to other source points, the other sinks to the confluence point n+1, and then is the ordinary maximum flow problem, with the EDMONDS_KARP algorithm to solve, the queue<int> Q write in while (true) outside than write in the inside faster 500ms

#include <cstdio> #include <cstring> #include <queue> #include <algorithm>using namespace std; int const INF = 0x3fffffff;int Const MAX = 105;int c[max][max];int f[max][max];int a[max];int pre[max];int N, NP, NC, M;in    T Edmonds_karp (int s, int t) {int ans = 0;    Queue <int> q;        while (true) {memset (A, 0, sizeof (a));        A[s] = INF;        Q.push (s);            while (!q.empty ()) {int u = q.front ();            Q.pop ();                    for (int v = 0; v <= n + 1; v++) {if (!a[v] && c[u][v] > F[u][v]) {                    A[v] = min (A[u], C[u][v]-f[u][v]);                    PRE[V] = u;                Q.push (v);        }}} if (a[t] = = 0) break;            for (int u = t; u! = s; u = Pre[u]) {F[pre[u]][u] + = a[t];        F[u][pre[u]]-= a[t];    } ans + = a[t]; } return ans; int main () {while (scanF ("%d%d%d", &n, &AMP;NP, &AMP;NC, &m)! = EOF) {memset (c, 0, sizeof (c));        memset (f, 0, sizeof (f));            for (int i = 0; i < m; i++) {int u, V, W;            scanf ("(%d,%d)%d", &u, &v, &w);        C[u + 1][v + 1] + = W;            } for (int i = 0; i < NP; i++) {int V, W;            scanf ("(%d)%d", &v, &w);        C[0][v + 1] + = W;            } for (int i = 0; i < NC; i++) {int u, W;            scanf ("(%d)%d", &u, &w);        C[u + 1][n + 1] + = W;    } printf ("%d\n", Edmonds_karp (0, n + 1)); }}




POJ 1459 Power Network (maximum stream base multi-source point Edmonds_karp algorithm)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.