Блог пользователя claporslap

Автор claporslap, 7 лет назад, По-английски

How can I calculate this with efficiency without using HLD or Link Cut Trees? I tried doing it with Binary Lifting but I am not able to do it correctly. Please guide me. Thanks.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

You are in the right path if you tried doing it using binary lifting. Have you managed to succeed in doing a regular binary lifting (just to find the LCA of 2 vertices)? If not I recommend you reading this blog

Now, if you understand how to find LCA of 2 vertices, you do almost the same thing you did for calculating the parenting array but instead you do it for the length of edges

pre-process example

For a query it is again very similar to finding the LCA of 2 vertices.