UVa 10793 - The Orc Attack

10793 - The Orc Attack

 * http://acm.uva.es/p/v107/10793.html

Summary
This is a straight-forward Graph Theory/Shortest Path problem.  Given L locations, you have to find a point such that it meets the following contraint: If there is more than one meeting that constraint, resolve by:
 * Is equidistant from point 1 to point 5.
 * Minimize the farthest point from each of the points.

Explanation
Run an all-pairs Shortest Path algorithm on the graph to obtain the full distance matrix, and then the rest is trivial.

Gotcha's

 * The point will have to be able to reach every single point. (This is only attainable if the graph is fully connected.)
 * If there is no such point (or if the graph is disconnected), output -1.
 * There might be more than one path from u to v - choose the shortest one.

Input
3 7 11 1 7 2 2 7 2 3 7 2 5 7 2 6 7 1 1 6 1 2 6 1 3 6 1 4 6 1 5 6 1 7 6 1 6 1 1 2 3 7 5 1 6 1 2 6 1 3 6 1 4 6 1 5 6 1

Output
Map 1: 1 Map 2: -1 Map 3: -1