Problem: There is a weighted tree with nodes and edges. The nodes are conveniently labeled from to . The weights are positive integers at most . Define the distance between two nodes to be the sum of edges on the unique path between the nodes. You would like to find the diameter of the tree. Diameter is the maximum distance between a pair of nodes.
Unfortunately, the tree isn't given to you, but you can ask some questions about it. In one question, you can specify two nonempty disjoint sets of nodes and , and the judge will return the maximum distance between a node in and a node in . In the words, maximum distance between and , where and . After asking not more than questions, you must report the maximum distance between any pair of nodes.
Note: In the first example, the first tree looks as follows:
In the first question, we have , and . The maximum distance between a node in and a node in is (the distance between nodes and ).
The second tree is a tree with two nodes with an edge with weight between them.