Update Dijkstra's algorithm to use a list of visited nodes.