Not quite sure about the Formula,but you can do this by using Sort and Advance Filter.First Sort the Cost then use Select the Origin & Destination Column Apply Advance Filter,checked unique record only..

You will get your desired result