Cheapest path algorithm from CSC321