inverse shortest path algorithm for a triangle in scala