Around the Track
Time limit1sMemory limit128 MB
Find the Eulerian circuit of a planar-ish graph whose total turning cost is minimized, where each degree-4 node requires choosing how to pair its incident edges.
- Level
Hard9 of 10
- Topics
- Graph, Dynamic programming, Greedy, Geometry
- Solved
- No attempts yet
Problem
After The Stig's identity was revealed, the car show Top Gear urgently needs a new, calm, and anonymous racing driver to replace him, and you have been asked to take the job. However, you are not very fond of driving fast, and especially not around the twisting and turning tracks used on the show. To ease this, one of your algorithmically minded friends suggests that you compute the roundtrip that requires the least total amount of turning.
The track consists of unique, straight roads (edges), and exactly or roads always head out of each junction (node). A roundtrip must be an Eulerian circuit: it must traverse every road exactly once and end where it started (such a circuit is guaranteed to exist in the input graph). The total amount of turning is the sum of the turning done at each node, where continuing straight through a node counts as a turn of . Roads can be driven in either direction.
When you enter a node along one road and leave along another, the turning is the absolute change of heading (in radians). If the angle between the two roads is , the turn equals : going straight () is , and a full U-turn () is . A degree- node is visited twice, so you may choose how to pair its four roads into two pairs, as long as the whole route forms a single Eulerian circuit.
Input
One line with the number of nodes and the number of edges , separated by a space.
lines with the and coordinates of each node, in order (). All nodes have distinct coordinate pairs.
lines with two integers and separated by a space, denoting an edge between nodes and . Nodes are -indexed.
Output
Output the least total amount of turning needed to complete an Eulerian circuit, in radians, rounded to exactly six decimal places.
Hint

Figure: an illustration of the track from the second example.