#M003. [模板题]最大流加强版

[模板题]最大流加强版

Problem Description

This is a template problem.

Given nn nodes and mm directed edges, each edge has a specified capacity. The task is to calculate the maximum flow from node ss to node tt.

Input Format

The first line contains four integers: n,m,s,tn, m, s, t.
The next mm lines each contain three integers: u,v,cu, v, c, representing a directed edge from node uu to node vv with a flow capacity of cc.

Output Format

Output the maximum flow from node ss to node tt.

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

Constraints and Hints

  • 1n12001 \leqslant n \leqslant 1200, 1m1200001 \leqslant m \leqslant 120000, 1c23111 \leqslant c \leqslant 2^{31}-1.
  • The answer is guaranteed to be less than or equal to 23112^{31}-1.
  • The time complexity of common maximum flow algorithms is O(n2m)O(n^2 \cdot m). Try to optimize your algorithm.