#P2454. [SCOI2008] 城堡 - 数据加强版
[SCOI2008] 城堡 - 数据加强版
Description
In a country, there are cities (numbered to ). These cities are connected by bidirectional roads (numbered to ). Road connects city and city (a road may connect a city to itself), with length . Among the cities, of them have their own castles, which can resist enemy invasions. When a city without a castle is attacked, the nearest castle will send troops to rescue.
Your task is to build castles in at most cities that currently do not have castles, so that the maximum “distance to the nearest castle” among all cities is as small as possible. In other words, let be the distance from city to its nearest castle; your goal is to minimize .
It is guaranteed that there exists a plan 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 already have castles.
Output Format
Output a single line containing one integer: the minimum possible 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
Constraints:
of the testdata satisfies and .
- Subtask 1: .
- Subtask 2: .
Translated by ChatGPT 5
京公网安备 11011102002149号