Editorial for IOI '02 P5 - Bus Terminals


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

The solution is based on the algorithm, running in O(n3) 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 D1 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 D2 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 D1 and D2. Next, output the minimum of D1 and D2 as the minimum diameter of the entire network.

First we will explain the computation of D1. If a point p will be served as the hub through which the longest route passes, the longest length is d(p,q)+d(p,r), where the points q and r is the farthest and the second farthest ones from p, respectively. Then D1=minp{d(p,q)+d(p,r)} over all points p of the input. This can be obtained in O(n2) time because the farthest and second farthest bus stops for each point p are easily found in O(n) time. Second we will explain how to compute D2 with a simple example. Note that in this case the longest route between two bus stops will pass both two hubs H1 and H2.

We consider all pairs of bus stops of the input as possible two hubs H1 and H2, and select the pair of the bus stops that gives a minimum diameter. Let at the beginning D2 be sufficiently large (e.g., maxint). Consider now fixed two hubs H1 and H2. Each of the remaining n2 points will be initially connected to one of two hubs, say H1. Sort the remaining n2 points in the array P in non-decreasing order according to the distance from the hub H1 (Figure 1).

Denote by r1=d(H1,P[n3]), r2=d(H2,P[n2]) and d12=d(H1,H2). If r1+d12+r2<D2, then the point P[n2] is connected to the hub H2 and set D2 to the new value D2=r1+d12+r2. Figure 2 represents this step, r1=d(H1,P[n3])=d(H1,P[4])=10, r2=d(H2,P[n2])=(H2,P[5])=3, d12=d(H1,H2)=12, so D2=r1+d12+r2=10+12+3=25. Now we repeat the same procedure with r1=d(H1,P[n4]), r2=d(H2,P[n3]), same d12=d(H1,H2), and get r1+d12+r2=d(H1,P[3])+d12+d(H2,P[4])=7+12+8=27. Since we got the new distance which is greater than the previous diameter, the value D2 remains unchanged, so D2 still has value 25. (If 25 is turned out to be the minimum of D2 at the end of the procedure, the point P[4] shall be connected to H1 although its distance to H2 is smaller than the distance from H1.) This situation is represented in Figure 3 where the point P[4] is connected with a thin line to H2 which is shorter than the distance from H1 to P[4].

This procedure is repeated by decreasing the index of the array P one by one until the index 1 is reached. For the example, the minimum value of D2 is 25 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 n2 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 O(n4) time. It considers all pairs of points as hubs H1 and H2, and computes D(H1,H2) for each pair in O(n2) 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

There are no comments at the moment.