A kingdom has N cities with M roads between them. You are given a 2D array E
denoting that there is a road between the cities E[i][0] and E[i][1] with a distance
of E[i] [2] for all Osis N-1.
Bob loves traveling very much and wants to travel the kingdom. He can start his
trip from any city and end the trip in any city he wants. However, he can't visit the
same city more than once.
You can perform the following operation exactly once:
Take one road with its distance and delete this road. Add it in another place
where there is no road, provided that all cities remain connected each
other(you can add the road in the same place where it was removed).
Find the minimum distance of the longest trip t Bob can take after performing the
above given operation.
Note:
Its guaranteed that there is a path between every two cities.
Input Format
The first line contains an integer, N, denoting the number of cities in the kingdom.
The next line contains an integer, M, denoting the number of rows in E.
The next line contains an integer, three, denoting the number of columns in E.
Each line i of the M subsequent lines (where 0 ≤ i < M) contains three space
separated integers each describing the row E[i].
Constraints
1 <= N <= 2000
N-1 <= M <= N-1
3 <= three <= 3
1 <= E[i][j] <= 10^5
Sample Test Cases
Case 1
Input:
2
1
3
1 2 2
Output:
2
Explanation:
Given N=2,, M = 1, three = 3, E= [[1, 2, 2]].
We can remove the road between cities 1, 2 and add it in the same place. So the
minimum distance of the longest trip is 2.
Case 2
Input:
3
2
3
1 2 1
2 3 2
Output:
3
Given N=3, M=2 ,three=3,E=[[1,2,1],[2,3,2]]
We can remove the road between cities 2,3 and it between 1,
3.So the minimum distance of the longest trip is 3.
case 3
input
3
2
3
1 2 2
1 3 3
output
5
Given N=3, M = 2, three = 3, E= [[1,2,2],[1,3,3]]
We can remove the road between cities 1,2 and add 2,3. So the minimum distance
of the longest trip is 5.