D - Transit Tree Path

  • image

  • Thoughts.

    • K is one whole
    • That is, if we pre-calculate the distances from K to all vertices, the query just adds up the lengths of the two paths
    • We can DFS K as the starting point and determine the distance of each vertex
  • Official Explanation


This page is auto-translated from /nishio/ABC070D using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I’m very happy to spread my thought to non-Japanese readers.