implement efficient djikstra's algorithm.