#P15607. [ICPC 2021 Jakarta R] Concerto de Pandemic
[ICPC 2021 Jakarta R] Concerto de Pandemic
题目描述
There are cities numbered from to . There is a bi-directional road connecting city to city for and city to city . Each road takes day to travel.
Due to a pandemic situation, there are cities that impose a quarantine order for any visitors to mitigate the pandemic spread in those cities. Specifically, whenever someone visits city , they will be quarantined for a duration of exactly days in a government-provided facility in that city. The order applies to any visitor including those who don't intend to stay in that city, e.g., only transiting.
Nawan is a rising young musician who already has die-hard fans. The fan lives in city , and surprisingly enough, none of the fans live in a city that imposes a quarantine order for visitors. Nawan has just released an album and now he wants to hold concerts for his die-hard fans. Despite rejections from his team, Nawan insists that the concert must be held live and in person; he believes that he wouldn't be able to convey his "musical feeling" to his fans through a virtual concert.
After considering the budget and their resource, Nawan and his team agree to hold at most concerts. Moreover, These concerts can only be held in cities that are not imposing any quarantine order for visitors. Nawan has contacted all of his fans and each of them agrees to attend only concert. The only remaining issue is in choosing the cities where Nawan should have a concert.
Each of the fans will attend a concert in which the venue requires the minimum travel time from their city. Each concert venue has no maximum capacity. Nawan wishes to hold the concerts in at most cities such that the longest travel time among all of his fans is as minimum as possible. Since Nawan needs to practice and prepare for the concerts, he asked you to choose the cities in which he should have a concert such that the longest required travel time by any fan is as minimum as possible; you only need to output the minimum longest travel time.
For example, let , , , , , , and . In this example, the concert venues should be in city and city with a longest travel time of only days.
- The fan at city will go to the concert at city , i.e. (quarantined for days) , for a total travel time of days.
- The fan at city will go to the concert at city where no travel is needed.
- The fan at city will go to the concert at city . i.e. , for a total travel time of days.
输入格式
Input begins with a line containing four integers (; ) representing the number of cities, the number of cities that impose a quarantine order, the number of Nawan's die-hard fans, and the maximum number of concerts to be held, respectively. The next lines each contains two integers (; ) representing the city that has a quarantine order and its quarantine duration, respectively. It is guaranteed that all are unique. The last line contains integers () representing the city in which the fan lives in. It is guaranteed that no fan lives in a city that imposes a quarantine order for visitors, and all fans live in a different city.
输出格式
Output contains an integer in a line representing the minimum longest travel time needed by any fan to reach a concert venue.
10 4 3 2
1 2
4 4
6 2
7 5
2 5 8
4
8 1 3 5
1 5
4 2 7
0
5 2 2 1
1 14
2 14
3 5
1
提示
Explanation for the sample input/output #2
Nawan can hold a private concert for each of his fans, i.e. the concert venues should be in cities , , and .