Implement dijkstra algorithm