Problem D
Evacuation
A city specified by a set of districts and bridges is under threat. Initially, each district can reach any other district through some series of bridges.
A tornado has touched down at district
Given the tornadoes predicted course you must determine the
minimum time it would take to travel from your home located in
district
Due to their size, residing in the same district as the tornado poses no threat.
Input
The first line of input will contain three integers,
The next line of input contains two integers
The following
The final line contains
Output
Output a single integer indicating the minimum amount of
time it will take to reach district
Sample Input 1 | Sample Output 1 |
---|---|
4 3 4 2 4 1 2 1 2 3 1 3 4 1 1 2 3 4 |
2 |
Sample Input 2 | Sample Output 2 |
---|---|
4 3 2 1 4 1 2 1 2 3 1 3 4 1 2 3 |
-1 |
Sample Input 3 | Sample Output 3 |
---|---|
6 6 3 1 3 1 2 3 2 3 3 1 5 2 5 3 2 4 5 1 5 6 1 4 5 3 |
6 |