#P3305. [SDOI2013] 费用流
[SDOI2013] 费用流
Description
Alice and Bob studied maximum flow and minimum-cost maximum flow in their graph theory course.
Maximum flow problem: Given a directed graph representing a transportation network, a source and a sink , each edge has a maximum capacity.
A valid network flow must satisfy:
- The actual flow on every edge is non-negative and does not exceed its capacity;
- Except for the source and the sink , for every other vertex, the total inflow equals the total outflow; the net outflow from equals the net inflow to , and this value is the total shipped amount (the value of the flow).
The maximum flow problem is to find, for the given network, a flow with the maximum total shipped amount.

The figure above illustrates a maximum flow instance. For each edge, the number on the right is the edge capacity, and the number on the left is the actual flow on that edge in an optimal solution. Note that a maximum flow solution may not be unique.
For a given transportation network, Alice first determines a maximum flow. If there are multiple solutions, Alice may choose any one of them. After that, Bob assigns a unit cost to each edge (each unit cost must be a non-negative real number), subject to the constraint that the sum of unit costs over all edges equals .
The total cost equals the actual flow on each edge multiplied by its unit cost, summed over all edges. Note that Bob knows the maximum flow solution chosen by Alice before assigning unit costs. Alice wants to minimize the total cost, while Bob wants to maximize it. We want to know, if both players use optimal strategies, what are the maximum flow value and the total cost.
Input Format
The first line contains three integers . is the number of vertices in the transportation network, is the number of directed edges, and is as defined in the statement. To simplify the problem, assume the source is vertex and the sink is vertex .
Each of the next lines contains three integers , indicating a directed edge from to with capacity .
Output Format
Output two lines. The first line contains an integer, the maximum flow value. The second line contains a real number, the total cost. It is recommended to print at least 4 decimal places.
3 2 1
1 2 10
2 3 15
10
10.0000
Hint
【Sample Explanation】
For Alice, the maximum flow is fixed. The actual flow on both edges is .
For Bob, assign a cost of to the first edge and to the second edge. The total cost is . It can be proven that no assignment yields a larger total cost.
【Constraints】
For of the testdata, the capacity of every directed edge is .
For of the testdata, , .
For of the testdata: all vertex labels are in the range , , , and there are no self-loop edges.
Translated by ChatGPT 5
京公网安备 11011102002149号