Bug fix to dfs

Prior to this fix it was possible to visit nodes more than once when
using an array of nodes as roots.