#P3381. 【模板】最小费用最大流
【模板】最小费用最大流
Description
Given a directed graph (hereinafter referred to as a network) with vertices and edges. The vertices are numbered , and the edges are numbered . The source of the network is , and the sink is . Each edge has a capacity limit and a unit cost .
You need to assign a flow to each edge such that:
- (the flow on each edge does not exceed its capacity limit);
- , $\sum_{(i,p) \in E} f(i,p) = \sum_{(p,i) \in E} f(p,i)$ (for all vertices except the source and the sink, the total inflow equals the total outflow);
- $\sum_{(s,i) \in E} f(s,i) = \sum_{(i,t) \in E} f(i,t)$ (the total flow leaving the source equals the total flow entering the sink).
Define the network flow and the network cost .
You need to find the minimum-cost maximum flow of the network, that is, maximize and, subject to that, minimize .
Input Format
The first line contains four integers , representing the number of vertices, the number of edges, the index of the source, and the index of the sink, respectively.
Each of the next lines contains four integers , representing the start vertex, end vertex, capacity limit, and unit cost of the -th edge.
Output Format
Output two integers: the maximum flow and, subject to being maximum, the minimum cost .
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
Hint
Constraints:
For of the testdata, , , , , , and the network’s maximum flow and minimum cost .
The testdata is randomly generated.
Translated by ChatGPT 5
京公网安备 11011102002149号