Deep within the verdant embrace of an ancient, whispering forest lies a marvel of arcane construction: the Enchanted Labyrinth. Conceived by the archmages of a forgotten era, this labyrinth guards the legendary Crystal of Aeternum, a gem of untold power. While many have braved the labyrinth's convoluted corridors in search of glory, only the echoes of their valor remain, a testament to the maze's perilous nature. The labyrinth is a network of $$$N$$$ mystic chambers, linked by $$$M$$$ pathways of uniform length, with only $$$K$$$ chambers harboring portals that lead back to the realm of men.
Elisa, a daring explorer driven by tales of the ancient relic, finds herself ensnared within the labyrinth's spellbound walls. From the initial chamber labeled $$$1$$$, she must navigate through the maze to reach a portal that promises freedom. However, the labyrinth is not without its sentinel – a cunning Minotaur, tasked with thwarting the escape of intruders by manipulating the very fabric of the maze.
The Minotaur, bound to the magic of the labyrinth, has the power to seal any one pathway leading from the chamber in which Elisa currently resides, effectively blocking her passage through that route. However, its power is limited to the chamber's confines at Elisa's location, and once she embarks upon an unsealed pathway, the beast cannot obstruct her until she arrives at the subsequent chamber. In this deadly game of wits and wills, your challenge is to determine the shortest path that Elisa can take to ensure her escape or to despairingly conclude that the Minotaur's guile renders escape impossible, in which case, return $$$-1$$$.
The first line contains three integers, $$$N$$$, $$$M$$$, and $$$K$$$ ($$$1 \leq N \leq 10^6$$$, $$$1 \leq M \leq 2 \times 10^6$$$, $$$1 \leq K \leq N$$$), the number of chambers, the number of pathways, and the number of escape portals, respectively.
The next $$$M$$$ lines each describe a pathway with two integers $$$a$$$ and $$$b$$$ ($$$1 \leq a, b \leq N$$$), indicating a bidirectional path between chambers $$$a$$$ and $$$b$$$.
The last line enumerates $$$K$$$ distinct integers, the indices of chambers containing escape portals.
Output the minimum distance Elisa must traverse to ensure her escape. If the Minotaur's machinations make escape an impossibility, print $$$-1$$$.
5 7 21 21 32 32 43 44 53 53 5
3
5 7 11 21 32 32 43 44 53 55
-1
5 7 31 21 32 32 43 44 53 53 4 5
2
| Name |
|---|


