Poj1459--power Network (Network stream, super Source point, Meeting point)

Source: Internet
Author: User

Description

A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u May is supplied with A amount s (U) >= 0 of power, may produce a 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 a amount D (u) =s (u) +p (U)-C (U) of Powe R. The following restrictions Apply:c (U) =0 for all power station, P (U) =0 for any consumer, and P (u) =c (u) =0 to any Dispat Cher. There is at most one Power transport line (U,V) from node U to a node V in the net; It transports a amount 0 <= L (u,v) <= Lmax (u,v) of power delivered by U to 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 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 the Transport Line (U,V) shows that L (u,v) =x and Lmax (u,v) =y. The power consumed is con=6. Notice that there are possible states of the network but the value of Con cannot exceed 6.
Input

The

There are 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 <= 1000 is the value of Lmax (U,V). Follow np doublets (u) z, where U is the identifier's a power station and 0 <= Z <= 10000 is the value of Pmax (U). The data set ends with NC doublets (u) z, where you are the identifier of a consumer and 0 <= Z <= 10000 is the value of Cmax (U). All input numbers are integers. Except the (u,v) z Triplets and the (U) z doublets, which don't contain white spaces, white spaces can occur freely in Inpu T. Input data terminate with a end of file and are correct.
Output

For each data set from the input, the program prints on the standard output the maximum amount of the Can is consum Ed in the corresponding network. Each result has an integral value and is printed from the beginning of a separate line.
Sample Input

2 1 1 2 (0,1) 20 (1,0) 10 (0) 15 (1) 20
7 2 3 13 (0,0) 1 (0,1) 2 (0,2) 5 (1,0) 1 (1,2) 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

15
6

The idea is more difficult to understand. And a lot of nonsense, directly look at the input. First four number of n,np,nc,m,n to represent nodes, there are power plants, transformers, users and so on; the next is the M logarithm, the path in parentheses, then the flow; the next is the number of NP, the position of the power plant in brackets, the capacity of the outside, and the number of NC, which indicates the user
It is easy to see the number of power plants and users there are many, so to establish a super source point to connect all power plants, the capacity of the power plant to represent the flow of the path. In the same way, the user's capacity represents the traffic of the path by using the Super meeting point to connect all users. Then use the maximum flow to solve

#include <stdio.h> #include <string.h> #include <algorithm> #include <queue> #include < vector> #include <iostream> #include <set> #include <cstring> #include <string> #define MAXN 5
#define INF 0x3f3f3f3f using namespace std;
int n,np,nc,m; int FLOW[MAXN][MAXN],CAP[MAXN][MAXN],PRE[MAXN],A[MAXN];
    Flow, capacity, parent node, residuals void edmondskarp (int s,int t) {int u,v;
    Queue<int> Q;
    int f=0;
        while (1) {memset (a,0,sizeof (a));
        Q.push (s);
        A[s]=inf;
            while (!q.empty ())//bfs Find the grace path {U=q.front ();
            Q.pop ();
                    For (v=0 v<=n+1; ++v) {if (A[v]==0&&cap[u][v]>flow[u][v]) {
                    Pre[v]=u; A[v]=min (A[u],cap[u][v]-flow[u][v]);
                Find the minimum residual q.push (v) of the s-v path;
    The residual of all paths is 0, which indicates that the maximum flow break is already in the a[t]==0.    for (v=t; v!=s; v=pre[v])//Update the traffic of the path {flow[pre[v]][v]+=a[t];
        FLOW[V][PRE[V]]-=A[T];
    } F+=a[t];
printf ("%d\n", f);
    int main () {int u,v,w;
    Char ch;
        while (~SCANF ("%d%d%d%d", &n,&np,&nc,&m)) {memset (cap,0,sizeof (CAP));
        memset (flow,0,sizeof (flow)); for (int i=0; i<m; ++i)//input path, to reserve the location of the super source point {cin>>ch>>u>>ch>>v>>ch>&
            Gt;w;
        Cap[u+1][v+1]=w;
            for (int i=0;i<np;++i) {cin>>ch>>u>>ch>>w;//power station location, starting from Super Source point 0
        Cap[0][u+1]=w;
            for (int i=0;i<nc;++i)//user location, reach Super Meeting point n+1 {cin>>ch>>u>>ch>>w;
        Cap[u+1][n+1]=w;
    } edmondskarp (0,n+1);
return 0;
 }

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.