Modify BFS to maintain only one hash table of nodes.