return the cost of the path