Drawing a Tree
InterviewTime limit1sMemory limit1024 MB
Connect N given points with N-1 segments that form a tree and do not cross, then print the endpoint index pairs.
- Level
Medium4 of 10
- Topics
- Sorting, Implementation
- Solved
- No attempts yet
Problem
There are points on a two-dimensional plane. Draw line segments to form a tree. No two of the drawn segments may cross each other.
A segment crosses another when an endpoint of one lies on the other. Two segments that meet only at a shared endpoint do not cross.
Input
The first line contains the number of points . ()
The next lines each contain the coordinates of one point. The -th line contains the integers and , separated by a space. ()
All given points have distinct coordinates.
Output
Print lines that describe the segments forming the tree. Each line contains the numbers of the two endpoints, separated by a space.
If there are multiple valid trees, print any one of them.