costPerPath function

Cost per path