Faster version of shortest path lookup