#P7173. 【模板】有负圈的费用流
【模板】有负圈的费用流
Problem Description
Given a cost flow network with nodes and edges, with source and sink , find its maximum flow with minimum total cost.
Note that there are edges with negative cost and cycles whose total cost is negative.
Also note that in this problem, it is allowed to add a unit of flow to a cycle that does not pass through as a whole. In fact, if this situation is not allowed, then the Hamiltonian path problem can be reduced to this problem.
Input Format
The first line contains four positive integers .
Lines to each contain four integers , meaning that there is an edge from to with capacity and cost .
Output Format
Output one line with two integers, representing the maximum flow and the minimum cost, respectively.
4 5 4 3
4 2 30 2
4 3 20 3
2 3 20 1
2 1 30 9
1 3 40 5
50 280
5 7 1 5
1 3 2 4
1 2 2 3
3 5 2 2
3 2 1 -1
2 4 2 -2
4 3 1 -1
4 5 1 3
3 12
Hint
For of the testdata: , , .
Note: It is not sure whether a cycle-canceling algorithm can pass. Since the testdata is graded in subtasks, even if it cannot pass, you should still be able to get some points.
Translated by ChatGPT 5