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 " ruv " 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 representing a query. Output: For each query, write out the answer on a single line. Example: Input: 41223142142242 Output: 1 2 HTIP 1: start writing your answer from line 8 import sys \#this lines imports sys library input_from_question=input() \#Gets the Input def solution(input_from_question): \#\# WRITE YOUR ANSWER HERE \#\# \#TIP 2: use input() again to get input in different lines \#TIP 3: use input_from_question.split(' ') to get different values return print(solution(input_from_question)) \#printing the output

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!