luogu#P4722. 【模板】最大流 加强版 / 预流推进
【模板】最大流 加强版 / 预流推进
Problem Description
Given vertices and directed edges, with a capacity on each edge, find the maximum flow from vertex to vertex .
Input Format
The first line contains four positive integers , , , , separated by spaces, representing the number of vertices, the number of directed edges, the source vertex index, and the sink vertex index.
The next lines each contain three positive integers , , , separated by spaces, meaning that the -th directed edge starts from , ends at , and has capacity .
Output Format
Output one integer, the maximum flow from to .
7 14 1 7
1 2 5
1 3 6
1 4 5
2 3 2
2 5 3
3 2 2
3 4 3
3 5 3
3 6 7
4 6 5
5 6 1
6 5 1
5 7 8
6 7 7
14
10 16 1 2
1 3 2
1 4 2
5 2 2
6 2 2
3 5 1
3 6 1
4 5 1
4 6 1
1 7 2147483647
9 2 2147483647
7 8 2147483647
10 9 2147483647
8 5 2
8 6 2
3 10 2
4 10 2
8
Hint
Constraints: , , .
It is guaranteed that the answer does not exceed .
The time complexity of common network flow algorithms is , so please optimize your algorithm as much as possible.
testdata provider: @negiizhao.
(If anyone passes this problem using Dinic’s algorithm, please send a private message to the uploader.)
Translated by ChatGPT 5