#P1690. 贪婪的 Copy
贪婪的 Copy
Description
Copy heard from Lu Niu that many treasures are buried in a divine land called yz, so Copy came to this land, which is divided into regions. Lu Niu told Copy that there are in total treasures, each placed in region (). Copy also learned the distance between every pair of regions. Now Copy starts from region , wants to collect all treasures, and leave from region . Copy is lazy, so he asks you to find a suitable route that minimizes the total distance he needs to travel.
Input Format
- The first line contains a positive integer ().
- The next lines each contain integers; the number in row , column denotes the distance from region to region . The numbers are separated by spaces, and each distance is at most . Note that the distance is not necessarily equal to .
- The next line contains an integer ().
- The next line contains integers separated by spaces, denoting the indices of the regions that contain treasures.
Output Format
Output a single integer: the minimum total distance for Copy to collect all treasures and then reach region . The testdata guarantees that the answer is at most .
2
0 4
5 0
2
1 2
4
3
0 2 6
1 0 4
7 10 0
1
2
6
Hint
- For of the testdata, ; the rest are as stated.
- For of the testdata, all constraints are as stated.
Translated by ChatGPT 5
京公网安备 11011102002149号