secomo's blog

By secomo, history, 3 years ago, In English

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?

  • Vote: I like it
  • -21
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.