LCC '25 Contest 1 S2 - Haunted Mansion

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

You are in a haunted mansion with N rooms, numbered from 1 to N. You start in room 1, and your goal is to get to the exit in room N, which you will do by travelling through some of the M passages that connect the rooms. Any pair of rooms may be connected by a maximum of one passage. However, the haunted mansion houses K zombie nests that are located in rooms z_1, z_2, ..., z_k, where 1\leq z_i\leq N. 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, N, M, and K.

The next M lines contain 2 integers, x and y, denoting a passage between room x and room y.

The final line of input contains K integers, the rooms that contain zombie nests.

Output Specification

Output the shortest amount of time it takes you to reach room N. If it is not possible to reach room N, or if there exists no path to room N in which you do not encounter any zombies, output -1.

Constraints

Subtask 1 [20%]

2\leq N \leq 100

1\leq M \leq 40

1\leq K\leq 10

Subtask 2 [80%]

2\leq N \leq 2\cdot 10^4

1\leq M \leq 10^4

1\leq K \leq 100

Sample Input 1

6 7 2
1 2
2 6
1 5
2 5
2 4
4 5
4 3
3 5

Output for Sample Input 1

2

Sample Input 2

7 6 1
1 2
2 3
3 4
4 5
5 7
6 7
6

Output for Sample Input 2

-1

Comments

There are no comments at the moment.