Question: HandsOn 3 : Cut and Link You are given a tree with N nodes. The length of the path between two nodes in a tree

HandsOn 3: Cut and Link
You are given a tree with N nodes.
The length of the path between two nodes in a tree is the number of edges in the shortest (and only) path between these two nodes.
The longest path in a tree is a path between two nodes with the maximum possible length. Additionally, if the tree consists of only one node, the length of the longest path is 0.
We have to maximize the length of the longest path of the resulting tree after doing the following two operations (each operation exactly once) on the given tree in order:
First, choose any edge from the tree and cut that edge to obtain two new trees.
After that, add an edge between the two resulting trees to form a new tree. Formally speaking, you select a node from the first resulting tree and another node from the second resulting tree and add an edge between them to form anew single tree.
Find the maximum possible length of the longest path of the resulting tree.
Input Format
The first line contains an integer, Nenoting the number of nodes in the tree.
The next line contains an integen, M, denhting the number of rows in edges.
The next line contains an integer. de denoting the number of columns in edges.
Each line i of the M subsequent lines (whene 0 si mi) contains G space sepanated integers each describing the row edges [i].
Constraints
2N105
N-1MN-1
2C2
1edges[][]
HandsOn 3 : Cut and Link You are given a tree

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 Programming Questions!