QOJ.ac

QOJ

時間限制: 1.5 s 記憶體限制: 64 MB 總分: 100

#602. Minimum Cost Maximum Flow (Random Data)

统计

This is a template problem.

Given a graph where each edge has a capacity and a cost, a specific cost must be paid for each unit of flow through the edge. Given a source $1$ and a sink $n$, find the maximum flow and the minimum cost required to achieve that maximum flow.

Input

The first line contains two integers $n$ and $m$, representing the number of nodes and the number of edges, respectively.

Each of the following $m$ lines contains four integers $s_i$, $t_i$, $c_i$, and $w_i$, representing an edge from $s_i$ to $t_i$ with capacity $c_i$ and a cost of $w_i$ per unit of flow.

Output

A single line containing two integers, representing the maximum flow and the minimum cost to achieve that maximum flow, respectively.

Examples

Input 1

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

Output 1

6 24

Note

$1 \leq n \leq 400, 0 \leq m \leq 15000, w_i \geq 0$. It is guaranteed that the input data, intermediate results, and the answer fit within the range of a 32-bit signed integer.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.