This page is still under construction.

Parts of this page are still being built. What you see may change.

Claustrophobic Cows

Interview

Time limit1sMemory limit128 MB

Summary
Given up to 2000 points, find the unique pair with the smallest Euclidean distance and print their ids in increasing order.
Level

Medium6 of 10

Topics
Geometry, Divide and conquer, Sorting, Brute force
Solved
No attempts yet

Problem

Farmer John's NN cows are numbered 11 through NN, and they really hate being too close to one another.

Each cow ii is located at integer coordinates (Xi,Yi)(X_i, Y_i). The distance between two cows is the Euclidean distance (Xi−Xj)2+(Yi−Yj)2\sqrt{(X_i - X_j)^2 + (Y_i - Y_j)^2}.

Among all pairs of cows, exactly one pair is closest together. Find these two closest cows and print their id numbers in increasing order.

Constraints

  • 2≤N≤20002 \le N \le 2000
  • 1≤Xi≤1000001 \le X_i \le 100000
  • 1≤Yi≤1000001 \le Y_i \le 100000

Input

  • Line 1: A single integer NN.
  • Lines 2 to N+1N+1: Line ii contains the coordinates of cow ii as two space-separated integers XiX_i and YiY_i.

Output

  • Line 1: The ids of the two closest cows, in increasing order, separated by a single space.

Examples1

  1. Example 1

    Input
    9
    2 9
    5 9
    8 10
    11 7
    10 3
    5 1
    6 4
    2 5
    7 6
    
    Expected output
    7 9