P28825 [洛谷] Maximum Flow Enhanced / Push-Relabel
提高+
题目描述

Problem Description

Given \( n \) points and \( m \) directed edges, along with the capacity of each edge, find the maximum flow from point \( s \) to point \( t \).

Input Format

The first line contains four positive integers \( n \), \( m \), \( s \), and \( t \), separated by spaces, representing the number of points, the number of directed edges, the source point number, and the sink point number, respectively.

The next \( m \) lines each contain three positive integers \( u_i \), \( v_i \), and \( c_i \), separated by spaces, indicating that the \( i \)-th directed edge starts from \( u_i \), ends at \( v_i \), and has a capacity of \( c_i \).

Output Format

A single integer representing the maximum flow from \( s \) to \( t \).

Sample Input and Output

Input Sample #1

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

Output Sample #1

14

Input Sample #2

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

Output Sample #2

8

Notes

\( 1 \leqslant n \leqslant 1200, 1 \leqslant m \leqslant 120000, 1 \leqslant c \leqslant 2^{31}-1 \).

The answer is guaranteed to be no more than \( 2^{31}-1 \).

The common complexity of network flow algorithms is \( O(n^2 m) \). Please optimize your algorithm as much as possible.

Data provided by @negiizhao.

(If someone solves this problem using the Dinic algorithm, please contact the uploader privately.)

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
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