nbcosts function

Compute cost of edges