-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmincostmaxflow.cpp
More file actions
74 lines (63 loc) · 1.5 KB
/
Copy pathmincostmaxflow.cpp
File metadata and controls
74 lines (63 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<int N>
struct mincost_maxflow {
// assume no negative cost cycles
// assume no demands
// uses successive shortest path algo
struct edge {
int from, to;
ll capacity, cost, flow;
};
ll inf = 1e18;
int source, sink;
vector<int> g[N + 1];
vector<edge> edges;
int pre[N], in_queue[N];
ll dist[N];
void addEdge(int from, int to, ll capacity, ll cost) { // from and to should be in {1..N}
g[from].pb(edges.size());
edge.pb({from, to, capacity, cost, 0});
g[to].pb(edges.size());
edge.pb({to, from, 0, -cost, 0});
}
bool spfa() { // shortest path faster algo, returns 1 if path exists from source to sink
for (int i = 1; i <= n; i++) {
dist[i] = inf;
in_queue[i] = pre[i] = 0;
}
dist[source] = 0;
minheap<pair<ll, int>> queue;
queue.push({0, source});
while (queue.size()) {
auto v = queue.top().s; queue.pop();
}
}
void augment() {
}
void fixCosts() {
for (edge &e : edges) {
e.cost += dist[e.from] - dist[e.to];
}
}
pair<ll, ll> solve(int _source, int _sink) {
source = _source;
sink = _sink;
ll flow = 0, cost = 0;
spfa(); fixCosts();
while (spfa()) {
fixcosts();
augment();
}
return {flow, cost};
}
};
int main() {
return 0;
}