If you're still getting an MLE - do this


#1

Mark visited=true just after you push it to the queue. This will reduce the extra overhead of unnecessary recursion calls.