Cow Steeplechase
From USACO. Shape / Geometry. Solve the geometry problem "Cow Steeplechase".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 0
Hints
Horizontal fence (x1,x2,y) and vertical fence (x,y1,y2) intersect iff vertical.x is in [horizontal.x1, horizontal.x2] AND horizontal.y is in [vertical.y1, vertical.y2]. Model as bipartite graph: horizontals on left, verticals on right, edge = intersection.
Minimum fences to remove so no intersections remain = minimum vertex cover in bipartite graph. By Kőnig's theorem, min vertex cover size = max matching size.
N ≤ 250, O(V·E) DFS augmenting path matching works. Fences can be points (x1=x2 or y1=y2) — still valid, use inclusive bounds. Answer = max matching cardinality.
Cow Steeplechase
**From USACO.** Shape / Geometry. Solve the geometry problem "Cow Steeplechase".