A tree is a connected graph with no cycle. A tree with N vertices has N−1 edges.
The distance between two vertices is the smallest number of edges on a path from one vertex to the other. The diameter of a tree is the largest distance over all pairs of vertices.
Build a tree with the longest possible diameter under the conditions below.
- Call the root of the tree V.
- Call the distance from V to the farthest vertex D.
- For every i with 1≤i≤D, the number of vertices whose distance from V is exactly i is cnt[i].
Given the array cnt, print the largest diameter among the trees that satisfy the conditions.