Under construction

Still being built. Things may change

Drawing a Tree

Interview

Time limit1sMemory limit1024 MB

Summary
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 NN points on a two-dimensional plane. Draw N−1N - 1 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 NN. (2≤N≤1 0002 \le N \le 1\,000)

The next NN lines each contain the coordinates of one point. The ii-th line contains the integers xix_i and yiy_i, separated by a space. (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9)

All given points have distinct coordinates.

Output

Print N−1N - 1 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.

Examples2

  1. Example 1

    Input
    4
    0 0
    -1 0
    1 1
    1 -1
    
    Expected output
    2 1
    3 1
    4 1
    
  2. Example 2

    Input
    7
    1 1
    3 3
    4 0
    3 1
    4 -2
    6 -2
    4 -3
    
    Expected output
    1 4
    2 4
    4 3
    3 5
    5 6
    5 7