#C13754. Closest Pair of Points

    ID: 43327 Type: Default 1000ms 256MiB

Closest Pair of Points

Closest Pair of Points

In this problem, you are given a set of points on a 2D plane. Your task is to find a pair of points that have the minimum Euclidean distance between them. The Euclidean distance between two points ( (x_1,y_1) ) and ( (x_2,y_2) ) is given by:

[ d = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2} ]

If there are multiple pairs with the same minimum distance, output the first pair found in the order of the input. The input will be provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line contains an integer ( n ) which represents the number of points. ( n ) lines follow, each containing two space-separated integers ( x ) and ( y ) which represent the coordinates of a point. ( 2 \leq n \leq 10^5 ) (with a typical constraint lower in contest problems).

outputFormat

Output four integers in one line: the coordinates of the two points forming the closest pair in the order they are found (i.e., the one that appears first in the input and then the other). The format should be: "x1 y1 x2 y2". Note that if the distance is the same for more than one pair, choose the pair that is encountered first.## sample

5
1 2
4 6
7 8
2 1
3 4
1 2 2 1