Company: Infosys SP
Difficulty: medium
Rescue the Cat with Merged Ladders A cat is stranded on the roof of a skyscraper. To rescue the cat, you need a large ladder. Unfortunately, such a ladder is unavailable, but you are provided with n smaller ladders. Each ladder is structured as a tree, where nodes are numbered sequentially from 1 to m , with m being the number of nodes in every ladder. Each ladder is described by a list of edges, where each edge connects two nodes. For example: Ladder 1 : (1-2, 1-3) , (2-3) Ladder 2 : (1-2, 2-3) , (1-3) If you merge node 2 of ladder 1 with node 1 of ladder 2 , the resulting combined ladder would look like this: 3-1 - 11 - (21+12) - 22 - 32 , forming a ladder with a total length of 4 . Here, A i (e.g., 21 , 12 , etc.) represents the i th node of the A th ladder. You can combine two ladders by merging specific nodes from each ladder. When two nodes are merged, they effectively become one, forming a larger ladder. Input Format First line contains an integer n , denoting the number of ladd