Roads in Berland

Source: Codeforces 25C

  1. Read the problem and summarise the task requirements.

We are interested in the sum of all pairs shortest paths.

  1. How many new roads will be built, and how much time (asymptotically) can we spend assessing the impact of each of them?

  2. For a given pair of cities, can a new road (anywhere in Berland):
  3. For the outcomes above that are possible, characterise the circumstances in which each of them occurs.
  4. Can you test each pair of cities as fast as you found to be necessary in Question 2?
  5. Design an algorithm to solve the problem.

  6. Analyse the time complexity of your algorithm and estimate its running time.

  7. Implement this algorithm in code.
  8. Submit your program for judging!