LCC '25 Contest 1 S2 - Haunted Mansion
View as PDFYou are in a haunted mansion with  rooms, numbered from 1 to 
. You start in room 1, and your goal is to get to the exit in room 
, which you will do by travelling through some of the 
 passages that connect the rooms. Any pair of rooms may be connected by a maximum of one passage. However, the haunted mansion houses 
 zombie nests that are located in rooms  
, where 
. The nests produce infinitely many zombies that will split up and travel in all possible directions. Fortunately, the zombies travel slow. While it only takes you 1 second to travel through a passage, it takes the zombies 5 seconds to do so.
An encounter with the zombies will occur if you arrive at a room at the same time or after the zombies do. However, leaving a room at the same time the zombies arrive does not count as an encounter. Find the fastest way to the exit such that you do not encounter any zombies.
Input Specification
The first line of input contains 3 integers, , 
, and 
.
The next  lines contain 2 integers, 
 and 
, denoting a passage between room 
 and room 
.
The final line of input contains  integers, the rooms that contain zombie nests.
Output Specification
Output the shortest amount of time it takes you to reach room . If it is not possible to reach room 
, or if there exists no path to room 
 in which you do not encounter any zombies, output 
-1.
Constraints
Subtask 1 [20%]
Subtask 2 [80%]
Sample Input 1
6 7 2
1 2
2 6
1 5
2 5
2 4
4 5
4 3
3 5Output for Sample Input 1
2Sample Input 2
7 6 1
1 2
2 3
3 4
4 5
5 7
6 7
6Output for Sample Input 2
-1
Comments