#D1930. Maximum Flow
Maximum Flow
Maximum Flow
A flow network is a directed graph which has a and a . In a flow network, each edge has a capacity . Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the to the .
Constraints
Input
A flow network is given in the following format.
:
, is the number of vertices and edges of the flow network respectively. The vertices in are named with the numbers 0, 1,..., . The source is 0 and the sink is .
, , represent -th edge of the flow network. A pair of and denotes that there is an edge from to and is the capacity of -th edge.
Output
Print the maximum flow.
Example
Input
4 5 0 1 2 0 2 1 1 2 1 1 3 1 2 3 2
Output
3
inputFormat
Input
A flow network is given in the following format.
:
, is the number of vertices and edges of the flow network respectively. The vertices in are named with the numbers 0, 1,..., . The source is 0 and the sink is .
, , represent -th edge of the flow network. A pair of and denotes that there is an edge from to and is the capacity of -th edge.
outputFormat
Output
Print the maximum flow.
Example
Input
4 5 0 1 2 0 2 1 1 2 1 1 3 1 2 3 2
Output
3
样例
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2
3