# P3381 [TEMPLATE] minimum fee maximum flow, minimum fee of p3381 Template

Source: Internet
Author: User

P3381 [TEMPLATE] minimum fee maximum flow, minimum fee of p3381 Template
Description

For example, a network diagram and its source and sink points are provided. The maximum traffic and unit traffic fee are known for each edge, and the maximum network flow and the minimum fee are obtained.

Input/Output Format

Input Format:

The first line contains four positive integers N, M, S, and T, indicating the number of vertices, the number of directed edges, The Source Vertex sequence number, and the sink vertex sequence number.

Each row in the next M line contains four positive integers, ui, vi, wi, and fi, indicating that the I-th directed edge departs from the ui and reaches vi, the edge weight is wi (that is, the maximum traffic for this edge is wi), and the unit traffic fee is fi.

Output Format:

A row contains two integers, which are the maximum traffic and the minimum fee in the case of the maximum traffic.

Input and Output sample input sample #1:
4 5 4 34 2 30 24 3 20 32 3 20 12 1 30 91 3 40 5
Output sample #1:
50 280
Description

Time-Space limit: 1000 ms, 128 M

(BYX: The last two points are changed to 1200 ms)

Data scale:

For 30% of data: N <= 10, M <= 10

For 70% of data: N <= 1000, M <= 1000

For 100% of data: N <= 5000, M <= 50000

Example:

, The optimal solution is as follows:

The first stream is 4 --> 3, the traffic is 20, and the fee is 3*20 = 60.

The second stream is 4 --> 2 --> 3, the traffic is 20, and the fee is (2 + 1) * 20 = 60.

The third stream is 4 --> 2 --> 1 --> 3, the traffic is 10, and the fee is (2 + 9 + 5) * 10 = 160.

Therefore, the maximum traffic is 50. In this case, the minimum fee is 60 + 60 + 160 = 280.

Therefore, the output is 50 280.

Template question of SPFA billing flow,

Use SPFA to check whether it can be extended

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.