Given an undirected tree with N nodes. Every node has a weight assigned to it denoted by array W.
Among all the simple paths of length K in the given tree, Sam can choose to pick any path and traverse on it.
Help Sam choose a path such that the maximum weight node present on the path is as minimum as possible.
Return -1, if no such path exists.
Note:
Input
Output
Print an integer denoting the maximum weight node present on the path traversed by Sam.
Constraints
1≤N≤1051≤K≤N1≤u,v≤N1≤W[i]≤105
There are 3 simple paths of length 2 in the given tree,
Sam, can pick the path with the maximum weight 2.