Pay attention to the following questions:
1. All routes are bidirectional, and the traffic in both directions is equal.
2. When I first started writing the template, I wrote an error, but the reason is not clear.
The Code is as follows:
# Include <cstdio> # include <cstring> # include <queue> # include <algorithm> using namespace std; const int N = 110; const int INF = 10000; int S, t, M, n, flow [N] [N], cap [N] [N]; int p [N], a [N]; int maxFlow () {queue <int> q; memset (flow, 0, sizeof (flow); int f = 0; while (1) {memset (a, 0, sizeof (a); a [S] = INF; q. push (S); while (! Q. empty () {int u = q. front (); q. pop (); // if (u = T) break; (this is written at the beginning, but wa, if you know why, please leave a message to me. Thanks for (int v = 1; v <= n; ++ v) {if (! A [v] & cap [u] [v]> flow [u] [v]) {p [v] = u; a [v] = min (a [u], cap [u] [v]-flow [u] [v]); q. push (v) ;}}if (a [T] = 0) break; for (int u = T; u! = S; u = p [u]) {flow [p [u] [u] + = a [T]; flow [u] [p [u]-= a [T];} f + = a [T];} return f;} int main () {int icase = 0; while (scanf ("% d", & n), n) {scanf ("% d", & S, & T, & M); memset (cap, 0, sizeof (cap); while (M --) {int s, t, c; scanf ("% d ", & s, & t, & c); cap [s] [t] + = c; cap [t] [s] = cap [s] [t];} printf ("Network % d \ n", ++ icase); printf ("The bandwidth is % d. \ n ", maxFlow ());}}