Let be two positive integers. IMO-nation has villages, and some pairs of villages are connected by a road. For any two villages, the distance between them is defined as the minimum number of roads one needs to travel to get from one village to the other; if it is completely impossible to travel from one village to the other, then the distance between these two villages is defined to be infinite.
Alice, who just arrived IMO-nation, is doing her quarantine in some place, so she does not know the configuration of roads, but she knows and . She wants to know whether the furthest two villages have finite distance. To do so, for every phone call she dials to the IMO office, she can choose two villages, and ask the office whether the distance between them is larger than, equal to, or smaller than . The office answers faithfully (infinite distance is larger than .) Prove that Alice can know whether the furthest two villages have finite distance between them in at most calls.
, 2021
Solution
Let be the graph corresponding to IMO-nation, and let be the distance between and . Consider the following strategy.
1. Arbitrarily choose a village , and let .
2. For every , make one phone call asking for the distance between and .
3. If there exists such that , and there exists such that , then let , change to , and return to step 2.
4. Check whether every village is at distance at most from some ; if so, report that is connected. Otherwise, report that is not connected.
First we prove that this algorithm indeed determines whether is connected. Denote by the set at the end of the algorithm. By step 3, the points in must all belong to the same connected set (this can be proved by induction), so if step 4 reports that is connected, then is indeed connected. Conversely, if step 4 reports that is not connected, this means there exists such that . Suppose that is in fact connected; then for any , there must exist a shortest path from to , and its length is greater than . Moreover, on this path there must exist a point whose distance to a point in is at most . But then, at step 3, we should have obtained and returned to step 2, so the algorithm would not yet have ended, a contradiction. Hence the algorithm reports that is connected if and only if is indeed connected.
Next we prove that the number of phone calls required by this algorithm is at most . Note that we only make phone calls in step 2, and step 2 is repeated at most times, so it suffices to prove that . This is obvious when , so assume . Consider the connected set in which lies, and suppose . Consider a spanning tree on , and consider an Euler tour on this tree. Then we can certainly choose such that .
Now, since and are two distinct elements of , by step 3 the distance between the two points is at least , and hence . This shows that . Also note that we may set , and consider the path starting from to ; this distance likewise must be at least , that is, . Combining the two inequalities, we obtain , so . This completes the proof.