diff options
| author | Paul Jungeblut <paul.jungeblut@gmail.com> | 2016-10-06 22:40:32 +0200 |
|---|---|---|
| committer | Paul Jungeblut <paul.jungeblut@gmail.com> | 2016-10-06 22:40:32 +0200 |
| commit | dca5be0e8cb390f68f1fa70b6c6549c289c3caa3 (patch) | |
| tree | 603cd121478bf3e6ce76e9c2d3e23befda72ff67 | |
| parent | 66b9c77b34d376fcc7a23f8a6d98c7e8ba852ea2 (diff) | |
Min cost max flow typesetting.
| -rw-r--r-- | graph/minCostMaxFlow.cpp | 36 | ||||
| -rw-r--r-- | tcr.pdf | bin | 262287 -> 261970 bytes |
2 files changed, 15 insertions, 21 deletions
diff --git a/graph/minCostMaxFlow.cpp b/graph/minCostMaxFlow.cpp index 3b0c575..8d3ca4c 100644 --- a/graph/minCostMaxFlow.cpp +++ b/graph/minCostMaxFlow.cpp @@ -1,10 +1,10 @@ -typedef long long ll; -static const ll flowlimit = 1LL << 60; // Should be bigger than the max flow. -struct MinCostFlow { // Should be initialized with new. - static const int maxn = 400; // Should be bigger than the #vertices. - static const int maxm = 5000; //#edges. - struct edge { int node; int next; ll flow; ll value; } edges[maxm << 1]; - int graph[maxn], queue[maxn], pre[maxn], con[maxn], n, m, source, target, top; +static const ll flowlimit = 1LL << 60; // Größer als der maximale Fluss. +struct MinCostFlow { // Mit new erstellen! + static const int maxn = 400; // Größer als die Anzahl der Knoten. + static const int maxm = 5000; // Größer als die Anzahhl der Kanten. + struct edge { int node, next; ll flow, value; } edges[maxm << 1]; + int graph[maxn], queue[maxn], pre[maxn], con[maxn]; + int n, m, source, target, top; bool inqueue[maxn]; ll maxflow, mincost, dis[maxn]; @@ -37,38 +37,32 @@ struct MinCostFlow { // Should be initialized with new. while (point != -1) { node = edges[point].node; - if (edges[point].flow > 0 && dis[node] > dis[now] + edges[point].value) { + if (edges[point].flow > 0 && + dis[node] > dis[now] + edges[point].value) { dis[node] = dis[now] + edges[point].value; pre[node] = now; con[node] = point; if (!inqueue[node]) { inqueue[node] = true; queue[tail++] = node; tail %= maxn; - } - } + }} point = edges[point].next; - } - } + }} return pre[target] != -1; } void extend() { ll w = flowlimit; - for (int u = target; pre[u] != u; u = pre[u]) { + for (int u = target; pre[u] != u; u = pre[u]) w = min(w, edges[con[u]].flow); - } maxflow += w; mincost += dis[target] * w; for (int u = target; pre[u] != u; u = pre[u]) { edges[con[u]].flow -= w; edges[inverse(con[u])].flow += w; - } - } + }} void mincostflow() { - maxflow = 0; - mincost = 0; - while (SPFA()) { - extend(); - } + maxflow = mincost = 0; + while (SPFA()) extend(); } }; Binary files differ |
