Hurry the Hedgehog
InterviewTime limit5sMemory limit2048 MB
Find the shortest path from intersection 1 to n that uses only intersections with a Super Mushroom, and print its number of intersections.
Problem
Hurry is a hedgehog who lives in the Mushroom Kingdom. He is on a mission to save Princess Plum from the evil Donkey Kong. To reach the Princess, Hurry must run through a hyperspace network of roads. These roads are dangerous. Each road he walks between two intersections exposes him to attacks from Space Invaders. Some intersections have a Super Mushroom that restores Hurry's health.
Find the shortest path through the network such that Hurry eats a Super Mushroom at every intersection on the path.
Input
The intersections are numbered from to . Hurry starts at intersection and must run to intersection .
The input is structured as follows:
- One line with three integers: , the number of intersections; , the number of roads; and , the number of Super Mushrooms.
- One line with integers: the indices of the intersections that have a Super Mushroom. Intersections and always have a Super Mushroom and are not in this list.
- lines with two integers each, indicating that there is a road between the two intersections with these indices.
Output
One line containing one integer: the number of intersections on the path Hurry has to run.