in this question , what i am planning to do is form a graph with given condition . if condition is : a e , means a should be drunk before e . i am adding a edge from a to e . i will use a map<int,set> to control internal sorting according to input . But how to control disconnected components . like in the given first sample , c and d are separated .
I have a doubt , how to connect disconnected components
if i apply topological sorting starting from A , it will output only the connected components with A . so , how should i incorporate c and d ?
and moreover those c and d nodes , should come before many nodes of the connected componenets of A
topological sorting will not take the effect of input sorting thing !
@JARVIS17 You can consider any component first. Then use topological sort in the component to maintain the order. As one component ends run topological sort in other component.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.