Optimize `findPaths`.