rewrite in nonrecursive form

This is basically a straight port that just enqueues path/node
pairs in a queue instead of recursing. This is nicer to our stack,
but it seems to have impacted efficiency.