Bones's Battery
Time limit5sMemory limit128 MB
Find the smallest battery range so every pair of schools connects with at most K charges over roads within range.
- Level
Medium5 of 10
- Topics
- Binary search, Graph, Shortest path
- Solved
- No attempts yet
Problem
Bones is shopping for an electric shuttle for the school district where his mother works. Every school has a charging station. Call the range of the shuttle the greatest distance it can drive on a full charge.
A trip from any school to any other school has to finish with at most rechargings. The shuttle's battery starts out empty, so it must be charged before it sets off, and that charge counts toward the . It may be charged again at any school it stops at along the way.
At most one road runs between any pair of schools, and every pair of schools is joined by some sequence of roads. Given the road network and , find the smallest range the electric shuttle needs.
Input
The first line has one integer (), the number of test cases.
Each test case begins with a line of three integers , , and (, ), where is the number of schools, is the largest number of rechargings allowed on one trip, and is the number of roads.
Each of the next lines has three integers , , and (, , ). Road joins school and school in both directions and has length . Schools are numbered from 0.
Output
For each test case, print the smallest required range on one line.