正文
增加 9 行删除 9 行
2 行未改动3456789101142 行未改动54555657585960616235 行未改动989910010110210310410510626 行未改动1331341351361371381391401415 行未改动1471481491501511521531541551561571581591601611621631641651664 行未改动2 行未改动**引入**:可以理解为有一个自来水厂要运水,每个管道最大通过的流量为 $w_i$。**实现**:可以通过 BFS 找一条新路线直到没得找了,每次找到新路线计算最大流。**容量约束**:因为通过的流量不能大于 $w_i$ 所以当前路径的最大流不能大于当前路径里最小的边权。**反悔**:为了解决错误的路径选择,所以允许流量回流,允许返回。**核心逻辑**:通过不断寻找并利用增广路径来逐步增加总流量,直到无法找到新的增广路径为止。42 行未改动**功能**:通过 BFS 找一条从 $s$ 到 $t$ 的路径。**计算最大流**:```cppll wll(ll s, ll t) {ll v, u, d, mfw = 0;while (bfs(s, t)) { // 循环寻找增广路径35 行未改动ll vis[100000]; // 防止重复访问ll bfs(ll s, ll t) {memset(pre, -1, sizeof(pre)); // 初始化为-1memset(vis, 0, sizeof(vis));queue<int> q;vis[s] = 1; // 标记源点已访问q.push(s);26 行未改动d = min(d, cap[u][v]); // 找路径上的瓶颈容量v = u;}mfw += d; // 累计到总流量// 更新残留网络v = t;while (v != s) {u = pre[v];5 行未改动return mfw;}signed main() {std::ios::sync_with_stdio(false);cout.tie(0); cin.tie(0);cin >> n >> m >> x >> t;for (int i = 1; i <= m; i++) {cin >> a >> b >> c;cap[a][b] += c; // 处理重边:直接累加容量}ll al = wll(x, t);cout << al;return 0;4 行未改动2 行未改动3456789101142 行未改动54555657585960616235 行未改动989910010110210310410510626 行未改动1331341351361371381391401415 行未改动1471481491501511521531541551561571581591601611621631641651664 行未改动2 行未改动**引入**:可以理解为有一个自来水厂要运水,每个管道最大通过的流量为 $w_i$。**实现**:可以通过 BFS 找一条新路线直到没得找了,每次找到新路线计算最大流。**容量约束**:因为通过的流量不能大于 $w_i$ 所以当前路径的最大流不能大于当前路径里最小的边权。**反悔**:为了解决错误的路径选择,所以允许流量回流,允许返回。**核心逻辑**:通过不断寻找并利用增广路径来逐步增加总流量,直到无法找到新的增广路径为止。42 行未改动**功能**:通过 BFS 找一条从 $s$ 到 $t$ 的路径。**计算最大流**:```cppll wll(ll s, ll t) {ll v, u, d, mfw = 0;while (bfs(s, t)) { // 循环寻找增广路径35 行未改动ll vis[100000]; // 防止重复访问ll bfs(ll s, ll t) {memset(pre, -1, sizeof(pre)); // 初始化为-1memset(vis, 0, sizeof(vis));queue<int> q;vis[s] = 1; // 标记源点已访问q.push(s);26 行未改动d = min(d, cap[u][v]); // 找路径上的瓶颈容量v = u;}mfw += d; // 累计到总流量// 更新残留网络v = t;while (v != s) {u = pre[v];5 行未改动return mfw;}signed main() {std::ios::sync_with_stdio(false);cout.tie(0); cin.tie(0);cin >> n >> m >> x >> t;for (int i = 1; i <= m; i++) {cin >> a >> b >> c;cap[a][b] += c; // 处理重边:直接累加容量}ll al = wll(x, t);cout << al;return 0;4 行未改动