Weights Distributing

Source: Codeforces 1343E

  1. Read the problem and summarise the task requirements.

Let’s try the problem with a (over-)simplifying assumption.

  1. Suppose the least cost path a → b → c is guaranteed to use each edge at most once. Which edges do we need to assign costs for, and how should we assign those costs?

Let’s reconsider our assumption more carefully.

  1. Is it possible for the least cost path a → b → c to repeat an edge?
  2. For a particular case of the above structure, which edges do we need to assign costs for, and how should we assign these costs?

  3. How many such cases are there? How long does the assignment of edge costs take? Is there a data structure that can improve upon the brute force approach?

  4. Design an algorithm to solve the problem.

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

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