Segments
Time limit1.1sMemory limit16 MB
Given N integer points, pick K distinct segments with the minimum total length and report the points that every optimal choice must use.
- Level
Medium7 of 10
- Topics
- Geometry, Heap, Sorting, Implementation
- Solved
- No attempts yet
Problem
Vlad really enjoys drawing points on a piece of paper. He has been doing it all day long, but now he decides that he wants to join some of these points using straight lines. There are such points, numbered from to , and all of them have integer coordinates. Vlad wants to draw exactly distinct line segments. For each segment, he chooses both endpoints from the points he has already drawn. He also wants to minimize the total length of the segments, which is the sum of the lengths of the segments.
You will help Vlad find the minimum total length and all the mandatory points. A point is mandatory if it is an endpoint of at least one of the segments in every choice of segments that reaches the minimum total length. In other words, if you erase a mandatory point, you cannot reach the same minimum length.
Input
The first line has two positive integers and . The following lines contain the coordinates of each point. All coordinates are integers. The points are numbered from to .
Output
On the first line, print the minimum total length with an error of at most (the first 4 decimals must be correct). The following lines contain the indices of the mandatory points in ascending order.
Constraints
- All coordinates are integers in the range .
- The coordinates of the points are not necessarily distinct.
- A point may be used as an endpoint for any number of line segments.