Editorial for Balkan OI '11 P5 - Time Is Money


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.

When t = c, the problem is a simple minimum spanning tree, because minimizing t \times c = t^2 is the same as minimizing t.

When t and c are different, different solutions can generate different trade-offs between \sum t and \sum c. It is straightforward to optimize for t only or c only, and it is also straightforward to optimize for t+c, because the sum in the total cost can be distributed to sums over individual links: \sum t + \sum c = \sum(t+c).

The next step is to optimize for a weighted sum of t and c, at+bc. This corresponds in the solution space to point left-most of a line with the slope -\frac b a. By varying the \frac b a ratio the lower convex hull of points in the solution space can be determined.

This already leads to a simple solution which consists of sweeping the range of values for \frac b a but we do not know yet when the sweep is fine-grained enough to determine all points. A more precise approach consists of finding a solution which optimizes time, a solution optimizing money and then using the slope of the line connecting them. You then continue recursively for the two pairs formed by the new solution with the previous solution. You stop when you don't find a new solution which is not already colinear to the two points.

Finding the points on the lower convex hull is sufficient because the curve defining solutions of equal cost is convex (a hyperbola, s \times t = constant). The number of points on the lower convex hull is limited by the fact that coordinates are integer (maximum 199 \times 255) and the slope between consecutive points on the hull has to vary.


Comments

There are no comments at the moment.