Constructed dijkstra algorithm