Misha, Grisha and Underground

Source: Codeforces 832D

  1. Read the problem and summarise the task requirements.
  2. How many cases arise from each query?

  3. In each of these cases, we are interested in the edges common to two paths. How can we decompose the paths to highlight the edges in common?
  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!