Design a data structure that maintains a directed graph.There is a node initially with label = 0, having no edges. The data-structure supports following queries:
Create : Create a new node, with label assigned with increasing value(previous added label). Add a directed edge from node 0 to this new node and then return label of new node.
Add(a, b) : Add a directed edge from node a to node b. Ignore if there is already an edge from a to b.
Delete(a, b): Delete the directed edge from node a to node b, and also delete all the nodes of graph which are not reachable from node 0. return the list of deleted edges and nodes.
He asked me to solve in O(logN) time complexity. It took me 40 mins to think the solution. I was unable to code it.