P4722 [Template] Maximum Flow Enhanced / Push-Relabel

Description

Given $n$ vertices and $m$ directed edges, with a capacity on each edge, find the maximum flow from vertex $s$ to vertex $t$.

Input Format

The first line contains four positive integers $n$, $m$, $s$, $t$, separated by spaces, representing the number of vertices, the number of directed edges, the source vertex index, and the sink vertex index. The next $m$ lines each contain three positive integers $u_i$, $v_i$, $c_i$, separated by spaces, meaning that the $i$-th directed edge starts from $u_i$, ends at $v_i$, and has capacity $c_i$.

Output Format

Output one integer, the maximum flow from $s$ to $t$.

Explanation/Hint

Constraints: $1\leqslant n \leqslant 1200$, $1\leqslant m \leqslant 120000$, $1\leqslant c \leqslant 2^{31}-1$. It is guaranteed that the answer does not exceed $2^{31}-1$. The time complexity of common network flow algorithms is $O(n^2 m)$, 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