The time penalty for a HashSet is significant in this case!
Jan bacha li dost! samjh hi nhi aa rha tha visited se bhi error aayega.