// Network stream-maximum stream <br/> // Add the virtual source point and virtual sink point diagram, convert to the shortest path from source to sink <br/> # include <iostream> <br/> # include <cstring> <br/> # include <queue> <br/> # define INF 2000000000 <br/> using namespace STD; <br/> int N, NP, NC, M; <br/> int X, Y, C, p, F, maxflow, St, Ed, U, V; <br/> int CAP [105] [105], flow [105] [105]; <br/> int rflow [105], pre [105]; <br/> int main () <br/> {<br/> // freopen ("in.txt", "r", stdin ); <br/> while (scanf ("% d", & N, & NP, & NC, & M )! = EOF) <br/>{< br/> maxflow = 0; <br/> memset (Cap, 0, sizeof (CAP); <br/> memset (flow, 0, sizeof (flow); <br/> ST = N; <br/> ED = n + 1; <br/> for (INT I = 0; I <m; ++ I) <br/> {<br/> scanf ("% * [^ (] (% d, % d) % d", & X, & Y, & C); // For the magic input method, refer to discuss on poj, you can also use sscanf to implement <br/> CAP [x] [Y] = C; <br/>}< br/> for (INT I = 0; I <NP; + + I) <br/>{< br/> scanf ("% * [^ (] (% d) % d", & P, & F ); <br/> CAP [st] [p] = f; // Add a virtual source to connect the source and the power station <br/>}< br/> (Int I = 0; I <NC; ++ I) <br/>{< br/> scanf ("% * [^ (] (% d) % d ", & C, & F); <br/> CAP [C] [ed] = f; // Add a virtual sink point, connect the electric appliance and the sink <br/>}< br/> for (;) // The maximum flow template <br/>{< br/> queue <int> q; <br/> memset (rflow, 0, sizeof (rflow); <br/> rflow [st] = inf; <br/> q. push (ST); <br/> while (! Q. empty () <br/>{< br/> U = Q. front (); <br/> q. pop (); <br/> for (V = 0; v <= Ed; ++ v) <br/>{< br/> If (! Rflow [v] & Cap [u] [v]> flow [u] [v]) // The residue is not marked and the capacity is greater than the current traffic, this node can be expanded <br/>{< br/> rflow [v] = min (rflow [u], cap [u] [v]-flow [u] [v]); // update the minimum node residual value <br/> pre [v] = u; // precursor pointer <br/> q. push (V); <br/>}< br/> If (rflow [ed] = 0) break; // The collection point is not marked, indicating that no augmented path is found in the residual volume network. <br/> for (u = Ed; u! = ST; u = pre [u]) // traverse the augmented path from the sink point by the forward pointer <br/>{< br/> flow [pre [u] [u] + = rflow [ed]; // update the forward current traffic <br/> flow [u] [pre [u]-= rflow [ed]; // update the reverse current traffic <br/>}< br/> maxflow + = rflow [ed]; // update the maximum stream <br/>}< br/> printf ("% d/N", maxflow); <br/>}< br/> return 0; <br/>}