is x ancestor to b ?

Правка en1, от secomo, 2021-07-08 23:57:03

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?

Теги #trees, ancestor

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский secomo 2021-07-08 23:57:03 371 Initial revision (published)