IOI '02 P5 - Bus Terminals
View as PDFIOI '02 - Yong-In, Korea
Yong-In city plans to build a bus network with  bus stops. Each bus
stop is at a street corner. Yong-In is a modern city, so its map is a
grid of square blocks of equal size. Two of these bus stops are to be
selected as hubs 
 and 
. The hubs will be connected to each
other by a direct bus line and each of the remaining 
 bus stops
will be connected directly to either 
 or 
 (but not to
both), but not to any other bus stop.
The distance between any two bus stops is the length of the shortest
possible route following the streets. That is, if a bus stop is
represented as  with 
-coordinate 
 and 
-coordinate
, then the distance between two bus stops 
 and
 is 
. If bus stops
 and 
 are connected to the same hub 
, then the length of
the route from 
 to 
 is the sum of the distances from 
 to
 and from 
 to 
. If bus stops 
 and 
 are connected
to different hubs, e.g., 
 to 
 and 
 to 
, then the
length of the route from 
 to 
 is the sum of the distances from 
to 
, from 
 to 
, and from 
 to 
.
The planning authority of Yong-In city would like to make sure that every citizen can reach every point within the city as quickly as possible. Therefore, city planners want to choose two bus stops to be hubs in such a way that in the resulting bus network the length of the longest route between any two bus stops is as short as possible.
One choice  of two hubs and assignments of bus stops to those hubs is
better than another choice 
 if the length of the longest bus route is
shorter in 
 than in 
. Your task is to write a program to compute
the length of this longest route for the best choice 
.
Input Specification
Your program is to read from standard input. The first line contains one
positive integer  
, the number of bus stops. Each
of the remaining 
 lines contains the 
-coordinate followed by the
-coordinate of a bus stop. The 
- and 
-coordinates are positive
integers 
. No two bus stops are at the same location.
Output Specification
Your program is to write to standard output. The output contains one line with a single positive integer, the minimum length of the longest bus route for the input.
Sample Input 1
6
1 7
16 6
12 4
4 4
1 1
11 1
Sample Output 1
20
Sample Input 2
7
7 9
10 9
5 3
1 1
7 2
15 6
17 7
Sample Output 2
25
The following figures show the bus networks for the inputs given above.
If in Example  bus stops 
 and 
 are selected as hubs then the longest
route is either between bus stops 
 and 
 or between bus stops 
 and 
.
There is no better choice for the hubs, and the answer is 
.
For the bus network in Example , if bus stops 
 and 
 are selected as
hubs then the longest route is obtained between bus stops 
 and 
. There
is no better choice for the hubs, and the answer is 
.
Comments