#P3376. 【模板】网络最大流
【模板】网络最大流
Description
As stated, given a network graph and its source and sink, compute the maximum flow of this network.
Input Format
The first line contains four positive integers , denoting the number of vertices, the number of directed edges, the index of the source, and the index of the sink, respectively.
Each of the next lines contains three positive integers , meaning that the -th directed edge goes from to with capacity (i.e., the maximum flow on this edge is ).
Output Format
One line containing a single positive integer, which is the maximum flow of the network.
4 5 4 3
4 2 30
4 3 20
2 3 20
2 1 30
1 3 30
50
Hint
Explanation for Sample Input/Output 1

There are paths in the figure:
- , which can carry a flow of .
- , which can carry a flow of .
- , which can carry a flow of (edge has already used units of flow beforehand).
Therefore, the total flow is . Output .
Constraints
- For of the testdata, it is guaranteed that , .
- For of the testdata, it is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号