Desert Travel
Time limit8sMemory limit1024 MB
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 - and -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 unit of distance traveled uses 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 to to , the maximum distance is about , the distance between and , because it is larger than the distance between and . 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 (), the number of oases. Each of the next lines contains two integers; the -th of these lines contains and ( and ), the coordinates of the -th oasis. The oases are numbered through .
The next line contains an integer (), the number of trips. Each of the next lines contains two integers; the -th of these lines contains and ( and ), the starting and ending oasis numbers for the -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 to oasis . Answers with absolute or relative error at most are accepted.