Distant Relatives
https://www.hackerrank.com/contests/codenection-2021-closed-category/challenges/distant-relatives
Question
Kyle has a family tree. It all started from a mysterious person, we call this person 1, the person had children, their children have children and so on. Any two children who share a common ancestor are called relatives, Kyle got an assignment from MMU to find how wide his family tree has spanned over the years, your task it to find the farthest relatives in his family tree to help him out.
(Edit : In the input, relationship means they have a connection. 1 4 means 1 and 4 have a connection. Either 1 is an ancestor of 4 or 4 is an ancestor of 1)
Input Format
Input consists of an integer N , the number of relatives and next N-1 lines contain relationship between children.
Constraints
Output Format
Output a single integer, the farthest distance of any two relatives on the family tree.
Sample Inputs:
Last updated