#graph601. 最大流

最大流

Maximum Flow

Problem Description

Given nn vertices, mm directed edges, and the capacity of each edge, find the maximum flow from vertex ss to vertex tt.

Input Format

The first line contains four integers n (1≤n≤100),m (1≤m≤5000),s,tn\ (1 \le n \le 100), m\ (1 \le m \le 5000), s, t.

Each of the next mm lines contains three integers u,v,cu, v, c, describing a directed edge from uu to vv with capacity c (0≤c≤231−1)c\ (0 \le c \le 2^{31} - 1).

Output Format

Output the maximum flow from vertex ss to vertex tt.

Sample Input

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

Sample Output

14