Problem G
Tima goes to Xentopia

The city of Xentopia has a well-connected railway network.
The city has
Tima, a tourist in the city, wants to travel from junction
Tima, being rather eccentric, has an interesting constraint
for her travel: She wants to travel via exactly
Can you tell the minimum time Tima will take to go from
Input
The first line contains four space-separated integers:
The last line contains two space-separated integers
Output
Print a single integer denoting the total time Tima would
take. If it is not possible for Tima to reach her destination
using exactly
Sample Input 1 | Sample Output 1 |
---|---|
4 4 1 1 1 2 1 2 1 3 1 0 2 4 1 1 3 4 1 0 1 4 |
2 |
Sample Input 2 | Sample Output 2 |
---|---|
4 3 200 1 1 2 1 1 2 3 1 0 2 4 1 2 1 3 |
-1 |