failed attempt to use graph algorithm stack overflow in depth first forest