is x ancestor to b ?

Revision en1, by 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?

Tags #trees, ancestor

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English secomo 2021-07-08 23:57:03 371 Initial revision (published)