Mandatory Play-doh

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Java 8 2.5s
Memory limit: 256M

Author:
Problem type

Oh no! Bob is at home, about to leave for school to attend his first period Calculus class, but he realizes that he is missing something very important. Bob and his class is on the unit Application of Integrals, and the teacher has requested all students to bring play-doh for some reason. However, Bob is an idiot, and forgot to bring play-doh with him beforehand. He does not want to get yelled at by the teacher.

Bob lives in a town with N buildings, numbered from 1 to N and there are M unweighted bidirectional roads connecting them. The i^{th} road connects building a_i and b_i.

There are K buildings s_1, s_2,... s_k which sell play-doh. Bob is currently at home in building A and his school is at building B. He needs to visit at least one of the K buildings to buy play-doh so he can be ready for class.

Bob wants to arrive at school as fast as possible, so help him find the length of the shortest way to do so.

Note that it is guaranteed that there exists a way. Bob is allowed to pass through B before buying the play-doh.

Input Specification

The first line of input will contain five space-seperated integers N, M, K, A, B

The next line of input will contain K space-seperated integers s_1, s_2,... s_k, representing the buildings that stores that sell play-doh.

The next M lines will contain two space-seperated integers, a_i and b_i.

Output Specification

Output a single integer, the shortest distance.

Constraints

1\le A, B, a_i, b_i, s_j \le N

1\le K \le N

1\le M \le {N \choose 2}

Subtasks 1 [30%]

1\le N \le 1\,000

1\le K \le 1\,000

1\le M \le 2\,000

Subtasks 2 [30%]

1\le N \le 100\,000

1\le K \le 10

1\le M \le 200\,000

Subtasks 3 [40%]

1\le N \le 100\,000

1\le K \le 100\,000

1\le M \le 200\,000

Sample Input 1

5 4 3 1 2
3 4 5
1 2
2 3
3 4
4 5

Output for Sample Input 1

3

Explanation of Output for Sample Input 1

Bob starts at his house which is at building 1. He passes by school at 2, to head to 3 to buy some play-doh. He then returns to 2, thus giving a total length of 3.

Sample Input 2

5 5 1 1 2
4
1 2
2 3
3 4
4 5
5 1

Output for Sample Input 2

4

Comments

There are no comments at the moment.