Editorial for IOI '02 P5 - Bus Terminals
Submitting an official solution before solving the problem yourself is a bannable offence.
The solution is based on the algorithm, running in time, presented in [1]. Recently, this algorithm is slightly improved in [2], but its implementation is too complicated to accept it for the competition, so we use the algorithm in [1] as a solution.
The diameter of a bus network is the longest length of the route between any two bus stops in the bus network. Our goal is to find the minimum value of the diameters over all possible choices of the hubs and assignments of bus stops. As did in [1], we consider two cases separately. For it, we need some notations. Let be the minimum value of the longest length between two bus stops which are connected through only one hub over all possible choice of one hub, and let be the minimum value of the longest length between two bus stops which are connected through both two hubs over all possible choice of two hubs and the corresponding assignments of bus stops. The diameter can be found in the following way presented in [1]. First, compute and . Next, output the minimum of and as the minimum diameter of the entire network.
First we will explain the computation of . If a point will be served as the hub through which the longest route passes, the longest length is , where the points and is the farthest and the second farthest ones from , respectively. Then over all points of the input. This can be obtained in time because the farthest and second farthest bus stops for each point are easily found in time. Second we will explain how to compute with a simple example. Note that in this case the longest route between two bus stops will pass both two hubs and .
We consider all pairs of bus stops of the input as possible two hubs and , and select the pair of the bus stops that gives a minimum diameter. Let at the beginning be sufficiently large (e.g., maxint
). Consider now fixed two hubs and . Each of the remaining points will be initially connected to one of two hubs, say . Sort the remaining points in the array in non-decreasing order according to the distance from the hub (Figure 1).
Denote by , and . If , then the point is connected to the hub and set to the new value . Figure 2 represents this step, , , , so . Now we repeat the same procedure with , , same , and get . Since we got the new distance which is greater than the previous diameter, the value remains unchanged, so still has value . (If is turned out to be the minimum of at the end of the procedure, the point shall be connected to although its distance to is smaller than the distance from .) This situation is represented in Figure 3 where the point is connected with a thin line to which is shorter than the distance from to .
This procedure is repeated by decreasing the index of the array one by one until the index is reached. For the example, the minimum value of is after the procedure and the corresponding network is shown in Figure 4.
Other approaches
Many contestants may take a (seemingly natural and intuitive) heuristic approach to connect each of bus stops to the nearest one of two hubs. But this is wrong because there is a counterexample. Of course, this approach can produce correct answers for some inputs.
We can make a brute force algorithm running in time. It considers all pairs of points as hubs and , and computes for each pair in time. But this approach will not produce the answer for large inputs within the time limit.
References
[1] J.-M. Ho, D. T. Lee, C.-H. Chang, C. K Wong, Minimum diameter spanning trees and related problems, SIAM J. on Computing, 20(5):987—997, 1991.
[2] T. Chan, Semi-online maintenance of geometric optima and measures, 13th ACM-SODA, 474—483, 2002.
Comments