Fixing unnecessary outer for loop in dijkstar shortest path