eolymp
bolt
Try our new interface for solving problems
Problems

In and Out

In and Out

The young pirate Will Twister has lost his precious medallion, once given to him by his father. It is now in the hands of governor Goose. Since this medallion is very dear to Will, he decides to steal it back. His presence will not go unnoticed (he's not a ninja), hence to increase his chances of a successful getaway he will use the cover of night. That does mean though that the journey to the governor's house will also be dangerous, because someone walking through town at night is suspicious. Throughout the town, sentries^1 are placed at strategically chosen junctions. Will is not a very good fighter, hence he will rely on the element of surprise and his speed to make it past them. However, if he were to pass the same sentry on both the journey to and from the governor's house, the element of surprise would be gone the second time and there is a big risk that he gets caught. Therefore, he does not want to pass the same sentry twice. Will's journey will start and end at the harbor, where he will arrive and leave by boat. He has a map of the town, complete with the locations of the sentries. Given that he'll have to do a lot of running, he wishes to find the shortest route to and from the governor's house that doesn't take him twice past any sentry. Can you help him determine this route? _______ ^1 - A sentry is a stationary guard. \InputFile The first line the number of test cases to follow. Each test case has the following format: \begin{itemize} \item One line with two integers \textbf{N }and \textbf{R} (\textbf{2 }≤ \textbf{N }≤ \textbf{1000}, \textbf{1 }≤ \textbf{R }≤ \textbf{10000}): the number of junctions and the number of roads, respectively. \item \textbf{R }lines, each with three integers \textbf{a}, \textbf{b }and \textbf{l} (\textbf{1 }≤ \textbf{a}, \textbf{b }≤ \textbf{N}, \textbf{1 }≤ \textbf{l }≤ \textbf{1000}), indicating that there is a bidirectional road between junctions \textbf{a }and \textbf{b }of length \textbf{l}. \item One line with one integer \textbf{S} (\textbf{0 }≤ \textbf{S }≤ \textbf{min(N-2}, \textbf{100)}): the number of sentries. \item One line with \textbf{S }distinct integers (\textbf{2} ≤ \textbf{s_i} < \textbf{N}), indicating that there is a sentry at junction \textbf{s_i}. \end{itemize} The junctions are numbered \textbf{1 }through \textbf{N}. Will's boat is at junction \textbf{1 }and the governor's house is at junction \textbf{N}. A path from the boat to the governor's house is guaranteed to exist. \OutputFile For every test case in the input, the output should contain one integer on a single line: the minimum total distance Will has to cover. If there is no route that passes each sentry at most once, the output should be "\textbf{No safe route}" (without the quotation marks) on a single line.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
6 7
1 2 1
2 3 1
3 6 1
1 4 10
4 3 10
2 5 10
5 6 10
2
2 3
5 5
1 2 1
1 3 2
2 4 1
3 4 2
4 5 1
1
2
5 5
1 2 1
1 3 2
2 4 1
3 4 2
4 5 1
1
4
Output example #1
42
8
No safe route
Source 2011 Benelux Algorithm Programming Contest, Preliminaries, Problem I