Http://www.acdream.net/problem.php? Id = 1042
Question:
(Both species and classification are considered as nodes .)
There is an unknown tree. One person asks for two leaf nodes each time, and the other person answers his/her LCA questions to determine whether there is a conflict between the answers.
Solution:
Sort each statement in ascending order of the depth of the LCA, and then scan the statement and check the set.
For example, if we get this statement: x y a, we can find the root node x_father y_father of XY. Because it is based on the depth of a from deep to shallow, so a must be the ancestor of x_father and y_father. Then we will discuss the possibility of this classification:
1. A is one of X (y) _ father:
1. x_father and y_father are both a: OK;
2. If x_father is equal to a, depth (y_father) must be greater than depth (A), and vice versa.
2. A is not one of X (y) _ father:
1. x_father and y_father are the same :! OK; (x_father = y_father indicates that the shaltest to shallow of xy is x_father, and depth (a) <= depth (x_father) &! = X_father => depth (a) <depth (x_father), so XY's LCA should not be)
2. x_father and y_father are different: As long as depth (a) <depth (x_father) & depth (a) <depth (y_father.
If it is correct after the discussion, check the set and continue.
There is a conflict in the middle, that is, wrong. If there is no conflict, a feasible solution can be provided based on the parallel process, maybe right.