A faster DFS implementation: (i) linear (ii) releases gil. Some assumptions in the original implementation (like using -9999 for tree root) are supported but can be optionally removed (a cleaner way of designating tree top is to add a self loop)