#P3044. [USACO12FEB] Relocation S
[USACO12FEB] Relocation S
Description
Farmer John is moving and wants to build a new farm so that his daily travel distance is minimized.
The region has towns (). There are bidirectional roads () connecting certain pairs of towns, and every town is reachable from every other town by some combination of roads. There are markets in towns () that FJ wants to visit every day. Each day, he will leave his new farm, visit all market towns in any order he chooses, and then return to his farm.
When choosing a town for his new farm, FJ will only consider the towns that do not have markets, since housing prices are lower in those towns.
Please compute the minimum total distance FJ needs to travel in his daily routine if he builds his farm in an optimal town and plans his route to the markets optimally.
Input Format
- Line 1: Three space-separated integers , , and .
- Lines : Line contains an integer in the range identifying the town containing the -th market. Each market is in a different town.
- Lines : Each line contains three space-separated integers , (), and (), indicating a bidirectional road of length between towns and .
Output Format
- Line 1: The minimum distance FJ needs to travel during his daily routine, if he builds his farm in an optimal location.
5 6 3
1
2
3
1 2 1
1 5 2
3 2 3
3 4 5
4 2 7
4 5 10
12
Hint
There are towns, with towns , , and having markets. There are roads. FJ builds his farm in town . His daily route is ------, for a total distance of .
Translated by ChatGPT 5
京公网安备 11011102002149号