Poj1459power Network (power grid)--Maximum flow problem

Source: Internet
Author: User

http://poj.org/problem?id=1459

Lengthy reading ...

Title Description:
A grid consists of nodes (power stations, consumers, dispatch stations) that are connected by wires. Each node u may
is supplied with S (U) energy, S (U) ≥0, and may also produce P (U) Power, 0≤p (U) ≤pmax (u); site u may also
Consumption C (U) electrical Energy, 0≤c (U) ≤min (S (u), Cmax (U)); May transmit D (U) energy, d (u) = S (u) + P (U)-C (U).
These quantities have the following limiting relationships: For each power station, c (u) = 0; For each consumer, p (u) = 0; For each dispatch station,
P (U) = c (U) = 0.
There is a maximum of one wire connected between the two nodes U and V in the grid. From junction u to Node v transmission L (u,v) of electrical Energy, 0≤l (u,v) ≤lmax (u,v). Defines the sum of con as C (U), which represents the sum of the consumed electricity in the grid. The purpose of the subject is to seek
The maximum value of Con.
An example of the grid is shown in 6.24. In figure (a), the marker "x/y" of the node U of the plant represents p (U) = x, Pmax (u) =
Y. The mark "x/y" of the consumer junction U stands for C (u) = x, Cmax (u) = y. Each wire corresponds to the Edge (U,V), which is labeled "X/Y"
Represents L (U,V) = x, Lmax (u,v) = y. In figure (b), the maximum energy con = 6 is consumed, and the figure (a) lists the
S (u), P (U), C (U), and D (U) for each site. Note that (b) in the grid shown, the flow of electrical energy exists in other states, but
The sum of electricity consumed is not more than 6.

Input Description:
The input file contains multiple test data. Each test data describes a grid. 1th Act of each test data 4
An integer: N np nc m, wherein, 0≤n≤100, represents the number of nodes, 0≤np≤n, the number of power plants; 0≤nc≤n,
Represents the number of consumers; 0≤m≤n2 represents the number of transmission wires. Next there are M triples, (U,v) z, where u and V
For the node ordinal (the node ordinal starts from 0), 0≤z≤1000, which represents the value of Lmax (U,V). Then there's NP two dollars.
Group, (U) z, where U is the serial number of the station node, 0≤z≤10000, which represents the value of Pmax (U); the last of each test data is
NC A two-tuple, (U) z, where U is the number of consumer nodes, 0≤z≤10000, represents the value of Cmax (U). All data
are integers. Except for triples (U,V) z and two-tuple (U) z, spaces are allowed in other locations in the input file. Test
Data until the end of the file.

Output Description:
For each test data in the input file described by the grid, the output of a row, an integer, indicating that the power grid can consume electricity
The maximum possible value.

The original power station, the consumer can not be as source and meeting point, add a source point and meeting point, the source point to the power station capacity of Pmax, consumer to meeting point capacity of Cmax, then the problem is converted to solve the maximum flow
The input of the topic is in regular expression sscanf (S, "(%d,%d)%d", &u,&v,&z);
Isap ...
memory:1060k time:110ms

#include <iostream>#include <cstring>#include <cstdio>#include <vector>Const intmaxn= the;Const intmaxm=1010;Const intinf=0x3f3f3f3f;using namespace STD;intN,s,t;structedge{intFrom,to,cap,flow; Edge (intUintVintCintf): From (U), to (v), Cap (c), Flow (f) {}}; vector<Edge>Edges vector<int>G[MAXN];intGAP[MAXN],D[MAXN],CUR[MAXN],P[MAXN];inline voidAddedge (intUintVintc) {Edges.push_back (Edge (U,v,c,0)); Edges.push_back (Edge (V,u,0,0));intM=edges.size (); G[u].push_back (M-2); G[v].push_back (M-1);}intIsap () {s=n,t=n+1; n+=2;memset(cur,0,sizeof(cur));memset(d,0,sizeof(d));memset(Gap,0,sizeof(GAP));intx=s,flow=0, A=inf; while(d[s]<n) {if(x==t) {flow+=a; while(x!=s)                {edges[p[x]].flow+=a; edges[p[x]^1].flow-=a;            X=edges[p[x]].from;        } A=inf; }intok=0; for(intI=cur[x];i<g[x].size (); ++i) {edge& e=edges[g[x][i]];if(e.cap>e.flow&&d[e.to]+1==d[x]) {p[e.to]=g[x][i];                Cur[x]=i;                x=e.to; ok=1; A=min (A,e.cap-e.flow); Break; }        }if(!ok) {intM=n; for(intI=0; I<g[x].size (); ++i) {edge& e =edges[g[x][i]];if(E.cap>e.flow) M=min (m,d[e.to]); }if(--gap[d[x]]==0) Break; gap[d[x]=m+1]++; cur[x]=0;if(x!=s) X=edges[p[x]].from; }    }returnFlow;}voidInit () {edges.clear (); for(intI=0; i<maxn;++i) G[i].clear ();}intMain () {intNp,nc,m; while(scanf("%d%d%d%d", &n,&np,&nc,&m)!=eof) {Init ();intU,v,z;Chars[Ten]; for(intI=0; i<m;++i) {scanf('%s ', s);sscanf(S,"(%d,%d)%d", &u,&v,&z);        Addedge (U,V,Z); } for(intI=0; i<np;++i) {scanf('%s ', s);sscanf(S,"(%d)%d", &u,&z);        Addedge (N,U,Z); } for(intI=0; i<nc;++i) {scanf('%s ', s);sscanf(S,"(%d)%d", &u,&z); Addedge (u,n+1, z); }intAns=isap ();cout<<ans<<endl; }return 0;}

Poj1459power Network (power grid)--Maximum flow problem

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.