版本比较
【网络流】最大流和最小割
正文
增加 19 行删除 19 行
55 行未改动565758596061606162636464656667684 行未改动7374757677777879808182838484858687889 行未改动989910010110210210310410510610710810910911011111211324 行未改动13813914014114214214314414514617 行未改动16416516616716816816917017117217317417417517617717829 行未改动2082092102112122132122132142152162162172182192202212222232232242252262279 行未改动2372382392402412412422432442452462472482482492502512525 行未改动25825926026126226226326426526626726826826927027127248 行未改动321322323324325325326327328329108 行未改动全部展开55 行未改动 int FF() { int c; while((c = dfs(S, inf)) != -1) { memset(vis, 0, sizeof vis); maxflow += c; } maxflow += c; } return maxflow; }``` ```
---
### Edmonds–Karp(EK)4 行未改动
时间复杂度为 $O(nm^2)$。
```cpp int aug[N] = {}, fa[N] = {}, d[N] = {}, now[N]; int aug[N] = {}, fa[N] = {}, d[N] = {}, now[N]; bool bfs() { memset(d, 0, sizeof d); memset(aug, 0, sizeof aug); memset(vis, 0, sizeof vis); queue <int> q; q.push(S); vis[S] = 1; aug[S] = inf, now[S] = head[S], d[S] = 1; vis[S] = 1; aug[S] = inf, now[S] = head[S], d[S] = 1; while(!q.empty()) { int p = q.front(); q.pop(); if(p == T) return 1;9 行未改动 } int EK() { int delta = 0; while(bfs()) { int x = T; int x = T; maxflow += (delta = aug[T]); while(x != S) { int i = fa[x]; w[i] -= delta, w[i ^ 1] += delta; x = To[i ^ 1]; } } } return maxflow; }```
24 行未改动 memset(aug, 0, sizeof aug); memset(vis, 0, sizeof vis); queue <int> q; q.push(S); vis[S] = 1; aug[S] = inf, now[S] = head[S], d[S] = 1; vis[S] = 1; aug[S] = inf, now[S] = head[S], d[S] = 1; while(!q.empty()) { int p = q.front(); q.pop(); if(p == T) return 1;17 行未改动 if(!c) d[to] = 0; w[i] -= c; w[i ^ 1] += c; rest -= c; } } } return flow - rest; } int Dinic() { int flow = 0; while(bfs()) while(bfs()) while(flow = dinic(S, inf)) maxflow += flow; return maxflow; }```29 行未改动 int FF() { int c; while((c = dfs(S, inf)) != -1) { memset(vis, 0, sizeof vis); maxflow += c; } maxflow += c; } return maxflow; } int aug[N] = {}, fa[N] = {}, d[N] = {}, now[N]; int aug[N] = {}, fa[N] = {}, d[N] = {}, now[N]; bool bfs() { memset(d, 0, sizeof d); memset(aug, 0, sizeof aug); memset(vis, 0, sizeof vis); queue <int> q; q.push(S); vis[S] = 1; aug[S] = inf, now[S] = head[S], d[S] = 1; vis[S] = 1; aug[S] = inf, now[S] = head[S], d[S] = 1; while(!q.empty()) { int p = q.front(); q.pop(); if(p == T) return 1;9 行未改动 } int EK() { int delta = 0; while(bfs()) { int x = T; int x = T; maxflow += (delta = aug[T]); while(x != S) { int i = fa[x]; w[i] -= delta, w[i ^ 1] += delta; x = To[i ^ 1]; } } } return maxflow; } int dinic(int x, int flow) { if(x == T) return flow;5 行未改动 if(!c) d[to] = 0; w[i] -= c; w[i ^ 1] += c; rest -= c; } } } return flow - rest; } int Dinic() { int flow = 0; while(bfs()) while(bfs()) while(flow = dinic(S, inf)) maxflow += flow; return maxflow; }} ;48 行未改动注意本题中猪可以在被打开的猪舍中调用,所以我们记录上一次打开这个猪舍 $x$ 的人,记为 $lst_x$。设当前这个人为 $i$。
+ $x$ 没有用过,将 $S$ 向 $i$ 连流量为这个猪舍的数量的边,相当于把整个猪舍移到这个人身上了,$i$ 相当于连接猪的桥梁。
+ $x$ 用过,那么 $i$ 就可以从 $x$ 处一直拿猪,从 $lst_x$ 到 $i$ 连边,流量为 INF。 + $x$ 用过,那么 $i$ 就可以从 $x$ 处一直拿猪,从 $lst_x$ 到 $i$ 连边,流量为 INF。
--------
### 蜥蜴108 行未改动全部展开