Added visited set in graph traversal.