#P2538. [SCOI2008] 城堡
[SCOI2008] 城堡
Description
In a country, there are cities (numbered to ). They are connected by bidirectional roads (numbered to ), where road connects city and city (a road may connect a city to itself) and has length . Among the cities, of them have their own castles and can resist enemy invasions. If a city without a castle is attacked, the nearest castle will send troops to rescue it.
Your task is to build castles in at most cities that currently do not have castles, so that the maximum among all cities of the distance to the nearest castle is as small as possible. In other words, let be the distance from city to its nearest castle; your task is to minimize .
The input guarantees that there exists a solution such that for every city, at least one castle can reach it.
Input Format
The first line contains three positive integers . The second line contains integers . The third line contains integers . The fourth line contains distinct integers between and , which are the indices of the cities that have castles.
Output Format
Output a single line containing one integer, the minimum value of .
5 0 1
1 2 3 4 0
1 1 1 1 1
2
3 1 1
1 2 0
1 2 3
2
1
2 1 1
0 1
1 1
1
0
10 3 3
0 2 0 0 2 2 8 3 8 7
10 9 1 8 1 3 7 2 8 1
3 4 6
3
2 0 1
1 0
5 10
5
Hint
of the testdata satisfies: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号