A small application of Dijkstra's algorithm to a nice problem