a shortest path calculation code segment