Classification of the species

Source: Internet
Author: User

Http:// Id = 1042


(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.


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.