Bones`s Battery
Bones is investigating what electric shuttle is appropriate for his mom's school district vehicle. Each school has a charging station. It is important that a trip from one school to any other be completed with no more than k rechargings. The car is initially at zero battery and must always be recharged at the start of each trip; this counts as one of the k rechargings. There is at most one road between each pair of schools, and there is at least one path of roads connecting each pair of schools.
Given the layout of these roads and k, compute the necessary range required of the electric shuttle.
Input
Starts with a line with the number of test cases t (1 ≤ t ≤ 50). Each test case begins with a line containing three integers n, k and m (2 ≤ n ≤ 100, 1 ≤ k ≤ 100), where n denotes the number of schools, k denotes the maximum number of rechargings permitted per trip, and m denotes the number of roads. Next follow m lines each with three integers u[i]
, v[i]
and d[i]
(0 ≤ u[i]
, v[i]
< n, u[i]
≠ v[i]
, 1 ≤ d[i]
≤ 10^9
) indicating that road i connects schools u[i]
and v[i]
(0-indexed) bidirectionally with distance d[i]
.
Output
For each test case, output one line containing the minimum range required.