Under construction

Still being built. Things may change

Desert Travel

Time limit8sMemory limit1024 MB

Summary
For each of up to 500,000 trips between oases, output the smallest canteen size, the minimum possible maximum Euclidean distance between consecutive stops along a path.
Level

Medium7 of 10

Topics
Minimum spanning tree, Graph, Math
Solved
No attempts yet

Problem

You are stranded in a desert. The desert can be viewed as a Cartesian plane. It contains many oases, and you know the xx- and yy-coordinates of each one. You will make a series of trips between pairs of oases; each trip has a starting oasis and an ending oasis. On any trip, you may stop at any number of other oases along the way.

Traveling in the desert requires water. Every 11 unit of distance traveled uses 11 unit of water. For each trip, you must choose the size of the canteen you will use. You want to use the smallest canteen that can complete the trip, since no one wants to carry more water than necessary.

You can refill the canteen at each oasis along the way so that it lasts until the next oasis. Therefore, the canteen size needed for a trip is the maximum Euclidean distance between consecutive oases on the trip's path. For example, if you travel from (0,0)(0,0) to (2,4)(2,4) to (4,5)(4,5), the maximum distance is about 4.4724.472, the distance between (0,0)(0,0) and (2,4)(2,4), because it is larger than the distance between (2,4)(2,4) and (4,5)(4,5). This distance determines the canteen size needed for the trip.

Given the number of oases and several trips, each with a starting oasis and an ending oasis, find for each trip the smallest canteen size needed, that is, the minimum possible maximum Euclidean distance between consecutive oases on a path between the two oases.

Input

The first line contains an integer OO (1≤O≤50001 \le O \le 5000), the number of oases. Each of the next OO lines contains two integers; the ii-th of these lines contains xix_i and yiy_i (−106≤xi≤106-10^6 \le x_i \le 10^6 and −106≤yi≤106-10^6 \le y_i \le 10^6), the coordinates of the ii-th oasis. The oases are numbered 11 through OO.

The next line contains an integer QQ (1≤Q≤5000001 \le Q \le 500000), the number of trips. Each of the next QQ lines contains two integers; the ii-th of these lines contains sis_i and eie_i (1≤si≤O1 \le s_i \le O and 1≤ei≤O1 \le e_i \le O), the starting and ending oasis numbers for the ii-th trip.

Output

For each trip, print on a line by itself one number: the smallest canteen size needed for that trip. This is the minimum possible maximum Euclidean distance between consecutive oases on a path from oasis sis_i to oasis eie_i. Answers with absolute or relative error at most 10−610^{-6} are accepted.

Examples1

  1. Example 1

    Input
    6
    0 0
    3 7
    1 2
    2 0
    4 5
    2 5
    3
    1 2
    6 5
    3 1
    
    Expected output
    3.1622776601683795
    2.0
    2.23606797749979