[INOI1302] Can someone help me find out what's the mistake in my code?

Sequence Land - CodeChef: Practical coding for everyone

My Code - INOI1302 - Pastebin.com

I’m creating a set for each person in the sequence land. I’m comparing elements between each person. If two people have more than K elements in common and also given that one of the them (Exactly one of them, it could be the first one or the second one but not both of them) have more than K elements in common with president, then I increment the total extended family value.

It fails in two test cases, can someone help me with this?

This question has something to do with the logic used to build breadth first search algo,
think !!.

queues …