Bridge Park
Time limit1sMemory limit512 MB
Given a connected planar straight-line graph on convex-position vertices, add the fewest non-crossing edges so the graph becomes 2-edge-connected.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
A park has small islands and bridges. The islands stand at the vertices of a convex polygon, a simple polygon whose interior angles are all smaller than 180 degrees. An island is a point and a bridge is a straight line segment. Every bridge joins exactly two islands, and two different bridges meet only at an island they share.
The bridges connect all islands, so a visitor standing on one island can walk to every other island.

One day a bridge broke and tourists were stranded on islands they could not leave. The park committee wants to build extra bridges so that all islands stay connected even after any single bridge breaks. An extra bridge is also a straight line segment between two islands, and it must not meet another bridge except at a shared island. Two islands that a bridge already joins cannot be joined again, because the new segment would lie on top of the old one.
Write for the bridge joining islands and . The park in the figure has the bridges , , , , , and . If breaks, the islands fall into the two groups and . If breaks, they fall into and . If breaks, all islands stay connected. Building the two bridges and makes the park survive the loss of any single bridge.
Given the islands and the bridges of the park, find the smallest number of extra bridges that keeps all islands connected after any single bridge breaks.
Input
The first line has two integers and (, ), the number of islands and the number of bridges. The islands are numbered through , and the list is the order in which they appear along the boundary of the convex polygon counterclockwise.
Each of the next lines has two integers and () describing the bridge . The given bridges connect all islands, and two different bridges meet only at an island they share.
Output
Print one integer on a single line: the smallest number of extra bridges such that all islands stay connected after any single bridge breaks.