Added memoizing version of shortest path. Untested.