Vivek and Party Problem


Why I’m getting a TLE?
Can you look into it?

Your topo sort implementation is a bit wrong. Look for Kahn’s algorithm for better understanding. You are only putting one more in queue as a start. Wherease you should put all the nodes with indegree zero into the queue.

https://ide.codingblocks.com/s/352257 How to pass another test case?

That’s for you now to see where it is failing as an implementation. Your logic is fine.

It might be failing for the lexicographical order implementation.
Now tell me how can i solve this?

See the topological sort will take care of the order. Now this question has multiple solutions ( depends on which order to take in a clash). So I think you should ask the problem setters to make sure this solution is accepting multiple solutions. Write it to [email protected]

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.