Festival 2 - MarisaOJ: Marisa Online Judge

Festival 2

Time limit: 1000 ms
Memory limit: 256 MB
The Human Village can be represented by a simple graph with $n$ locations and $m$ roads. The previous festival was very successful, so Reimu wants to organize an even grander festival. Specifically, she will choose a road to host the festival. There are $k$ people who want to attend the festival, and person number $i$ is currently at location $p_i$. Help Reimu choose a road to host the festival in such a way that the total distance the $k$ people have to travel to get to the festival is minimized. Each person only needs to travel to one end of the chosen road to reach the festival. ### Input - The first line contains three integers $n$, $m$, and $k$. - The second line contains $k$ integers $p_i$. - The next $m$ lines each contain two integers $u$ and $v$, representing an edge between vertices $u$ and $v$. ### Output - Print the minimum total distance. ### Constraints - $1 \le n,k \le 10^3$. - $1 \le m \le 3000$. - $1 \le u, v, p_i \le n$. ### Example Input: ``` 4 4 3 1 3 4 1 2 2 3 3 4 4 1 ``` Output: ``` 1 ```