P3044 [USACO12FEB] Relocation S

题目描述

Farmer John is moving! He is trying to find the best place to build a new farm so as to minimize the amount of travel he needs to do each day. The region to which FJ plans to move has N towns (1

输入格式

\* Line 1: Three space-separated integers, N, M, and K. \* Lines 2..1+K: Line i+1 contains an integer in the range 1...N identifying the town containing the ith market. Each market is in a different town. \* Lines 2+K..1+K+M: Each line contains 3 space-separated integers, i, j (1

输出格式

\* Line 1: The minimum distance FJ needs to travel during his daily routine, if he builds his farm in an optimal location.

说明/提示

There are 5 towns, with towns 1, 2, and 3 having markets. There are 6 roads. FJ builds his farm in town 5. His daily schedule takes him through towns 5-1-2-3-2-1-5, for a total distance of 12.