The European Rover Challenge (ERC) Space and Robotics Event is a prestigious space-robotics event combining international competitions of mobile robots with scientific and technological shows. University teams from around the world build their own Martian robots, and then take part in competitions similar to the tasks performed by rovers on the surfaces of Mars and the Moon. This year your university team has been selected to participate and you are the chief programmer of your team.
This year, the task of the competition is to collect valuable samples from the surface of Mars. Of course, it is a simulation area designed for the competition and the specifics are as follows:
Given the input parameters of the simulation area, find the minimum distance covered as output. Assume that it is always possible to carry all the samples to the retrieval location.
There maybe (
)
simulations in the competition and you have to complete all of them.
Each simulation starts with six integers: (
)
, the number of AoIs, (
)
- the number of roads connecting the AoIs, , , (), the three sample locations and, (), the retrieval location.
The next lines each contain three road parameters: , , (), where and are the connecting ends of the roads and, is the distance between the end AoIs. The starting location is always '1'.
Output only one integer for every simulation: the distance travelled by the robot while collecting all the samples and returning to the retrieval location using minimum battery energy.
Input | Output |
---|---|
1 6 6 3 5 4 6 1 2 1 2 3 1 2 5 1 5 4 1 2 4 1 4 6 1 | 6 |
Input | Output |
---|---|
2 10 11 5 2 7 10 1 2 1 1 3 2 2 3 5 3 5 1 3 4 2 5 4 2 4 6 5 6 7 6 6 8 1 8 10 3 8 9 3 10 15 5 7 9 10 1 2 1 1 3 2 2 3 5 4 7 4 3 5 1 3 4 2 2 6 2 5 4 2 4 6 5 6 7 6 6 8 1 7 9 1 8 10 3 8 9 3 6 10 7 | 28 16 |
Dataset can be large, use fast I/O methods.