From dca5be0e8cb390f68f1fa70b6c6549c289c3caa3 Mon Sep 17 00:00:00 2001 From: Paul Jungeblut Date: Thu, 6 Oct 2016 22:40:32 +0200 Subject: Min cost max flow typesetting. --- graph/minCostMaxFlow.cpp | 36 +++++++++++++++--------------------- 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(); } }; diff --git a/tcr.pdf b/tcr.pdf index d32246a..61788af 100644 Binary files a/tcr.pdf and b/tcr.pdf differ -- cgit v1.2.3