forked from cp-algorithms/cp-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_min_cost_flow.cpp
More file actions
45 lines (40 loc) · 990 Bytes
/
test_min_cost_flow.cpp
File metadata and controls
45 lines (40 loc) · 990 Bytes
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
#include <vector>
#include <queue>
#include <algorithm>
#include <cassert>
#include <iostream>
using namespace std;
#include "min_cost_flow_successive_shortest_path.h"
int main() {
// example from topcoder
vector<Edge> edges = {
{1, 2, 3, 1},
{1, 3, 3, 4},
{2, 3, 7, 2},
{3, 6, 1, 8},
{3, 5, 6, 5},
{3, 4, 5, 2},
{4, 5, 3, 1},
{0, 1, 5, 0},
{0, 2, 2, 0},
{4, 7, 2, 0},
{5, 7, 4, 0},
{6, 7, 1, 0},
};
vector<int> expected = {0, 4, 8, 14, 20, 26, 35, 47, -1};
for (int K = 0; K <= 8; K++) {
assert(expected[K] == min_cost_flow(8, edges, K, 0, 7));
}
// another example
edges = {
{0, 1, 3, 2},
{0, 2, 4, 6},
{1, 2, 3, 1},
{1, 3, 5, 6},
{2, 3, 2, 2}
};
expected = {0, 5, 10, 18, 29, 40, -1};
for (int K = 0; K <= 6; K++) {
assert(expected[K] == min_cost_flow(4, edges, K, 0, 3));
}
}