Ambulance Antics
Time limit2sMemory limit256 MB
Plan tours from the hospital that carry up to three patients each to bring every patient back in the least total driving time.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Shortest path, Combinatorics
- Solved
- No attempts yet
Problem
One ambulance has to carry patients who are scattered across the city to the hospital. The ambulance holds at most three patients at a time, and it has to drive back to the hospital to drop patients off. Loading and unloading take no time.
The city consists of intersections and streets. One intersection holds the hospital, and every other intersection holds one waiting patient. Every street is bidirectional, and each street has a driving time in minutes that is the same in both directions. The ambulance starts at the hospital.
The ambulance may pass through any intersection as many times as it likes. Compute the smallest number of minutes needed to bring every patient to the hospital. The ambulance stands at the hospital once the last patient is dropped off.
Input
The first line contains the number of test cases .
The first line of each test case contains two integers and , the number of intersections holding a patient and the number of streets. Each of the next lines contains three integers , , , meaning that a bidirectional street connects intersections and and that driving along it takes minutes.
The city has intersections, numbered 0 to . The hospital is at intersection , and one patient waits at each of the intersections 0 through .
- A route always exists between any two intersections.
- At most one street connects a given pair of intersections.
Output
For each test case, print one line with the minimum number of minutes needed to deliver every patient to the hospital.