Created djikstra function.