Woburn Challenge 2017-18 Round 4 - Senior Division
Desperate to find more allies to join in the fight against Thanos, the Avengers have requested assistance from Doctor Strange, a powerful magician. Strange is willing to help, but he'll need some assistance of his own first. To fully apply his powers to the fight, he'll need to gather together a set of artifacts from hidden sanctums around the world!
There are
There are
Doctor Strange is initially located in sanctum
Determine the minimum number of portal warps which Doctor Strange will
need to perform to achieve his goal. Unfortunately, it may instead turn
out to be impossible to visit the entire required sequence of sanctums,
in which case you should output -1
instead.
Subtasks
In test cases worth
In test cases worth another
Input Specification
The first line of input consists of two space-separated integers,
The next line consists of
Output Specification
Output a single integer, either the minimum number of warps required to
recover all of the artifacts, or -1
if not all of them can be recovered.
Sample Input 1
4 6
1 2
2 3
3 1
1 3
4 3
3 4
2
4 2
Sample Output 1
7
Sample Input 2
4 5
1 2
3 1
1 3
4 3
3 4
2
4 2
Sample Output 2
-1
Sample Explanations
In the first case, Doctor Strange can warp through the following sequence of sanctums:
In the second case, Doctor Strange would be able to recover the first
artifact and then reach the second one, but he would then be unable to
return to sanctum
Comments