Power networktime limit:2000msmemory limit:32768kbthis problem'll be judged onPKU. Original id:1459
64-bit integer IO format: %lld Java class name: Main 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.
InputThere 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.OutputFor each data set from the input, the program prints on the standard output the maximum amount of power that can is consum Ed 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
HintThe 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.SourceSoutheastern Europe 2003 Problem solving: maximum flow. The main topic is difficult to understand
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <climits>7#include <vector>8#include <queue>9#include <cstdlib>Ten#include <string> One#include <Set> A#include <stack> - #defineLL Long Long - #definePII pair<int,int> the #defineINF 0x3f3f3f3f - using namespacestd; - Const intMAXN = the; - intE[maxn][maxn],n,m,p,c,maxflow; + intd[maxn],q[100000],s,t,hd,tail; - BOOLBFs () { +memset (d,-1,sizeof(d)); AD[s] =0; atq[tail++] =S; - while(HD <tail) { - intU = q[hd++]; - for(inti =1; I <= N; i++){ - if(D[i] = =-1&& E[u][i] >0){ -D[i] = d[u]+1; inq[tail++] =i; - } to } + } - returnD[t] >0; the } * intDfsintUintLow ) { $ intA =0;Panax Notoginseng if(U = = T)returnLow ; - for(inti =1; I <= N; i++){ the if(E[u][i] >0&& D[i] = = d[u]+1&& (A =Dfs (I,min (low,e[u][i)))) { +E[u][i]-=A; AE[i][u] + =A; the returnA; + } - } $ return 0; $ } - intMain () { - Charch; the intu,v,w; - while(~SCANF ("%d %d%d%d",&n,&p,&c,&m)) {WuyiMemset (E,0,sizeof(e)); the for(inti =1; I <= m; i++){ -Cin>>ch>>u>>ch>>v>>ch>>W; Wue[u+1][v+1] +=W; - } AboutS = n+1; $T = n+2; -n + =2; - for(inti =1; I <= p; i++){ -Cin>>ch>>v>>ch>>W; Ae[s][v+1] +=W; + } the for(inti =1; I <= C; i++){ -Cin>>ch>>u>>ch>>W; $e[u+1][t] + =W; the } the intAns = Maxflow =0; the while(BFS ()) while(Maxflow = DFS (S,inf)) ans + =Maxflow; theprintf"%d\n", ans); - } in return 0; the}
View Code
POJ 1459 Power Network