summaryrefslogtreecommitdiff
path: root/graph/pushRelabel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'graph/pushRelabel.cpp')
-rw-r--r--graph/pushRelabel.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/graph/pushRelabel.cpp b/graph/pushRelabel.cpp
index 182fa12..da3ada7 100644
--- a/graph/pushRelabel.cpp
+++ b/graph/pushRelabel.cpp
@@ -1,73 +1,73 @@
struct PushRelabel {
- vector<vector<long long>> capacitie, flow;
- vector<long long> excess;
+ vector<vector<ll>> capacitie, flow;
+ vector<ll> excess;
vector<int> height, seen, list;
int n;
PushRelabel(int n) {
this->n = n;
- capacities.assign(n, vector<long long>(n));
- flow.assign(n, vector<long long>(n));
+ capacities.assign(n, vector<ll>(n));
+ flow.assign(n, vector<ll>(n));
excess.assign(n, 0);
height.assign(n, 0);
seen.assign(n, 0);
list.assign(n - 2, 0);
}
- inline void addEdge(int u, int v, long long c) {capacities[u][v] += c;}
+ inline void addEdge(int u, int v, ll c) {capacities[u][v] += c;}
void push(int u, int v) {
- long long send = min(excess[u], capacities[u][v] - flow[u][v]);
+ ll send = min(excess[u], capacities[u][v] - flow[u][v]);
flow[u][v] += send; flow[v][u] -= send;
excess[u] -= send; excess[v] += send;
}
- void relabel(int u) {
+ void relabel(int v) {
int minHeight = INT_INF;
- for (int v = 0; v < n; v++) {
- if (capacities[u][v] - flow[u][v] > 0) {
- minHeight = min(minHeight, height[v]);
- height[u] = minHeight + 1;
+ for (int u = 0; u < n; u++) {
+ if (capacities[v][u] - flow[v][u] > 0) {
+ minHeight = min(minHeight, height[u]);
+ height[v] = minHeight + 1;
}}}
- void discharge(int u) {
- while (excess[u] > 0) {
- if (seen[u] < n) {
- int v = seen[u];
- if (capacities[u][v] - flow[u][v] > 0 && height[u] > height[v]) {
- push(u, v);
- } else seen[u]++;
+ void discharge(int v) {
+ while (excess[v] > 0) {
+ if (seen[v] < n) {
+ int u = seen[v];
+ if (capacities[v][u] - flow[v][u] > 0 && height[v] > height[u]) {
+ push(v, u);
+ } else seen[v]++;
} else {
- relabel(u);
- seen[u] = 0;
+ relabel(v);
+ seen[v] = 0;
}}}
- void moveToFront(int u) {
- int temp = list[u];
- for (int i = u; i > 0; i--) list[i] = list[i - 1];
+ void moveToFront(int v) {
+ int temp = list[v];
+ for (int u = v; u > 0; u--) list[u] = list[u - 1];
list[0] = temp;
}
- long long maxFlow(int source, int target) {
- for (int i = 0, p = 0; i < n; i++)
- if (i != source && i != target) list[p++] = i;
+ ll maxFlow(int source, int target) {
+ for (int v = 0, p = 0; v < n; v++)
+ if (v != source && v != target) list[p++] = v;
height[source] = n;
excess[source] = INF;
- for (int i = 0; i < n; i++) push(source, i);
+ for (int v = 0; v < n; v++) push(source, v);
int p = 0;
while (p < n - 2) {
- int u = list[p], oldHeight = height[u];
- discharge(u);
- if (height[u] > oldHeight) {
+ int v = list[p], oldHeight = height[v];
+ discharge(v);
+ if (height[v] > oldHeight) {
moveToFront(p);
p = 0;
} else p++;
}
- long long maxflow = 0;
- for (int i = 0; i < n; i++) maxflow += flow[source][i];
+ ll maxflow = 0;
+ for (int v = 0; v < n; v++) maxflow += flow[source][v];
return maxflow;
}
};