Question: Problem Statement In a normal tree, the lowest common ancestor (or LCA for short) of two vertices u and v is defined as the lowest

 Problem Statement In a normal tree, the lowest common ancestor (or

LCA for short) of two vertices u and v is defined as

the lowest vertex that is ancestor of both the vertices. Given a

Problem Statement In a normal tree, the lowest common ancestor (or LCA for short) of two vertices u and v is defined as the lowest vertex that is ancestor of both the vertices. Given a tree of N vertices, you need to answer in the form "r uv " which means if the root of the tree is at r then what is LCA of u and v. Input: The first line contains a single integer N. Each line in the next N1 lines contains a pair of integers u and v representing an edge between these two vertices. The next line contains a single integer Q which is the number of the queries. Each line in the next Q lines contains three integers r, u, v represeming a query. Output: For each query, write out the answer on a single line. Coding ANELIQ Example: Input: 4 12 23 14 2 142 242 Output: 1 2 in the backend. Make sure you click the SUBMIT button to save and submit your

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!