Vivek and Birthday Celebration

Hello Sir,
I am getting in runtime error. I am solving this que through Disjoint set union .Please help me in optimising my solution.

Thanking you in advance.

@trojan_code forgetting about runtime error, I see incorrect approach of yours!
there are 2 simple cases:

  1. when atleast one person have no dependency, so just call this 1 person.
  2. otherwise just find the shortest cycle in directed graph(yes it’s a directed graph as inverse dependency are not valid).

Yes , Thank you . I got it