#P9901. 『PG2』弯曲半平面直线同向图最大流

『PG2』弯曲半平面直线同向图最大流

Problem Description

If a directed graph G=(V,E)G=(V,E) can be drawn on the plane such that all vertices lie on one straight line, any two edges (which may be curved arcs) intersect only at shared vertices, all points on every edge lie on the same side of the line, and the ray direction from the start point to the end point of each edge is the same, then GG is called a curved half-plane collinear same-direction graph. Given nn vertices and mm directed edges in such a graph, along with the capacity of each edge, find the maximum flow from vertex ss to vertex tt.

Input Format

The first line contains four positive integers nn, mm, ss, and tt, separated by spaces, representing the number of vertices, the number of directed edges, the index of the source vertex, and the index of the sink vertex.

The next mm lines each contain three positive integers uiu_i, viv_i, and cic_i, separated by spaces, indicating that the ii-th directed edge starts from uiu_i, ends at viv_i, and has capacity cic_i.

Output Format

Output one integer, representing the maximum flow from ss to tt.

5 7 1 5
1 2 1
2 3 1
3 4 1
4 5 1
2 4 1
1 4 1
1 5 1
2

Hint

There are no multiple edges or self-loops.

For 30%30\% of the testdata, n103n \leq 10^3.

For 70%70\% of the testdata, n105n \leq 10^5.

For 100%100\% of the testdata, 2n1062 \leq n \leq 10^6, $1 \leq m \leq \min\{2\times 10^9,\dfrac{n(n-1)}{2}\}$, 1c10121 \leq c \leq 10^{12}, and sts \neq t.

Sample Explanation 1

Translated by ChatGPT 5