bugfix: circular path detection was broken

We passed around a reference to the same set during
recursion but we need a (shallow) copy.

See the example. 1->2->4 (distance=2) was not found because the
depth-first recursion added 4 to the set of seen nodes in 1->2->3->4
(distance=3).