#M004. [模板题]最小费用流

[模板题]最小费用流

Problem Description

This is a template problem.

Given a graph where each edge has a capacity and a cost, using each unit of flow through an edge incurs a specific cost. Given a source node 11 and a sink node nn, find the maximum flow in the graph and the minimum cost required for the maximum flow.

Input Format

The first line contains two integers nn and mm, representing nn nodes and mm edges.

The following mm lines each contain four integers sis_i, tit_i, cic_i, wiw_i, representing an edge from node sis_i to node tit_i, with capacity cic_i and a unit flow cost of wiw_i.

Output Format

Output two integers: the maximum flow and the minimum cost required for the maximum flow.

Sample Input

8 23
2 3 2147483647 1
1 3 1 1
2 4 2147483647 2
1 4 1 2
2 8 2 0
3 5 2147483647 3
1 5 1 3
3 6 2147483647 4
1 6 1 4
3 8 2 0
3 2 2147483647 0
4 6 2147483647 5
1 6 1 5
4 7 2147483647 6
1 7 1 6
4 8 2 0
4 2 2147483647 0
5 8 0 0
5 2 2147483647 0
6 8 0 0
6 2 2147483647 0
7 8 0 0
7 2 2147483647 0

Sample Output

6 24

Data Constraints and Hints

  • 1n400,0m15000,wi01 \leq n \leq 400, 0 \leq m \leq 15000, w_i \geq 0
  • The input data, intermediate results, and the final answer are guaranteed to fit within a 32-bit signed integer.