Change of Scenery
Jump to navigation
Jump to search
This problem, though perhaps a bit confusingly stated, simply asks whether there are at least two shortest paths between two nodes. We can trivially run dijkstra's fast enough. To check whether there are multiple shortest paths, we can count. In dijkstra implementation, we add a second case. If the new path is SHORTER than the old path, we replace it as always, but if the new path is EQUAL to the old path, we increment the COUNT of shortest paths to that node by the count of shortest paths to our current node. If a shorter path is found, that count is set to the number of ways we reached the current node.
If there are multiple shortest paths, output yes. It seems the providing of the 'k' nodes is irrelevant.