// Network stream -- maximum stream <br/> // The condition for termination is that the path cannot be added to the residual network. <br/> // you need to consider multiple sides. <br/> # include <iostream> <br/> # include <queue> <br/> # include <cstring> <br/> # define INF 2000000000 <br/> using namespace STD; <br/> int n, m, U, V, X, Y, C, St, Ed; <br/> int flow [205] [205], cap [205] [205]; // current traffic, maximum capacity <br/> int rflow [205], pre [205]; // rflow indicates the residual traffic of each node, by the way, when the VIS array <br/> int maxflow; <br/> int main () <br/> {<br/> // freopen ("in.txt", "r ", stdin); <br/> whi Le (scanf ("% d", & M, & N )! = EOF) <br/>{< br/> maxflow = 0; <br/> ST = 1; <br/> ED = N; <br/> memset (flow, 0, sizeof (flow); <br/> memset (Cap, 0, sizeof (CAP); <br/> for (INT I = 0; I <m; + + I) <br/>{< br/> scanf ("% d", & X, & Y, & C ); <br/> CAP [x] [Y] + = C; // as multiple edges appear in the question, it is easier to save them using the adjacent matrix, so use + = to overlay the maximum traffic <br/>}< br/> for (;) <br/>{< br/> queue <int> q; <br/> memset (rflow, 0, sizeof (rflow); <br/> rflow [st] = inf; // set the starting stream to unlimited. <br/> q. push (ST); <br/> while (! Q. empty () <br/>{< br/> U = Q. front (); <br/> q. pop (); <br/> for (V = 1; v <= N; ++ v) <br/> {<br/> If (! Rflow [v] & Cap [u] [v]> flow [u] [v]) // if the residual traffic is equal to 0 (it indicates that it has not been updated) if the current capacity is greater than the current traffic, the change point can be expanded <br/>{< br/> pre [v] = u; // The precursor pointer record <br/> q. push (V); // Add to the queue <br/> rflow [v] = min (rflow [u], cap [u] [v]-flow [u] [v]); // The residual traffic at this point is (the residual traffic at the inbound point) and (the difference between the current capacity and the current traffic) <br/>}< br/> <br/> If (rflow [ed] = 0) break; // unable to find the augmented path to the settlement point, jump out <br/> for (u = Ed; u! = ST; u = pre [u]) // update traffic back from the sink <br/>{< br/> flow [pre [u] [u] + = rflow [ed]; // update forward traffic <br/> flow [u] [pre [u]-= rflow [ed]; // update reverse traffic <br/>}< br/> maxflow + = rflow [ed]; // update the total maximum stream <br/>}< br/> printf ("% d/N", maxflow); <br/>}< br/> return 0; <br/>}