Revised the shortest path

add pruning, which could significantly enhance performance.