Editorial for COCI '21 Contest 4 #1 Autići
Submitting an official solution before solving the problem yourself is a bannable offence.
We'll show that it's always best to connect the garage with the minimum  with the remaining 
 garages.
To connect all of them, we need at least  roads (initially there is only one garage, and for each additional one, we need one more road to connect it with the rest). In the optimal solution, we will build exactly 
 roads because it is never beneficial to connect two garages if there is already a path between them.
Therefore, the total length will be an expression consisting of  terms. Each garage needs to be connected to at least one road, so each of the numbers 
 must appear at least once in this expression. The smallest possible value of the remaining 
 terms is precisely the value of the smallest 
. Notice that this is actually achieved if we connect the garage with the smallest 
 with the rest.
Comments