Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор secomo, история, 3 года назад, По-английски

There is a tree that consists of one node(the root) let it be (1).

There is some queries each query is either

  1. find if x is ancestor of y.

  2. make x a son of y(its guaranteed that y exist).

If the first query does not exist its easy to solve it using DFS but I am stuck at finding a solution for the whole problem.

How to solve this?

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

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

This problem can be solved using Binary Lifting. I recommend watching the tutorial on Binary Lifting by Algorithms Live! on Youtube if you don't already know it.