Classes of graphs with an optimal shortest paths algorithm