You are on page 1of 2

Journey to Hogwarts

Harry Potter, and all the other eleven year old witches and wizards of England, have arrived at the Hogwarts School of Witchcraft and Wizardry after boarding the Hogwarts Express at Kings Cross Station (except for Malfoy Junior, who being a fraction late ended up in the hospital with a bandaged head). As per tradition, Hagrid the gamekeeper is waiting for all the younglings, to guide them across the lake to the castle in small magical boats. Now, each boat has space enough only for two little witches or wizards, and will not sail until exactly two little witches or wizards are comfortably seated in it. Also, the children have already made friends and foes on the train journey, and so refuse to sit with those they do not like. Not only this, naughty as they are, the little witches and wizards might jump boat, swim across, and attempt to switch partners. But they do not know that underneath the surface of the lake lurks the Giant Squid, who does not like to be disturbed by noisy, splashing brats. Hagrid, ever cautious, wants to ensure that such mid-trip reshuffle of little witches and wizards does not occur. Therefore, he will allow the boats to set sail if there is only a single arrangement of seating the children in pairs. He needs your help to decide if this is so, given the information about the kids friendship. Input Format First line contains a single integer T, denoting the number of test cases. Each test case is as follows: First line contains number of kids N. The next N lines contain the list of friends for each kid. The first line of every friend list denotes the number of friends m of that particular kid, followed by m space separated integers denoting the friends. The friendship is mutual i.e. it is guaranteed that if u occurs in the list of v, then v occurs in the list of u. [Kids are numbered from 1,2,,N] Output Format Print T lines, each line being a YES or NO (without the quotes) depending on whether Hagrid can allow the boats to make the trip. Constraints T<=25 N<=100 Sample Input 2 4 12 11 14 13

4 3234 3134 3124 3123 Sample Output


YES NO Explanation: st In the 1 test case, there is only one possible seating arrangement {(1,2) (3,4)}, so answer is YES In the 2 test case, everyone is friends with each other, so there are multiple arrangements:{ (1,2) , (3,4) } { (1,3) , (2,4) } { (1,4) , (2,3) } So answer is NO
nd

You might also like