You Might be a Redneck
View as PDFAfter proving his "intelligence" to Billy-Bob, Jim-Bob decides to give him a puzzle. He describes his family tree to Billy-Bob and asks him, "Am I a redneck?"
Jim-Bob's family consists of  
 people,
including himself. Person 
 has a name 
 with no spaces in it.
They also have 
 
 parents (sometimes Jim-Bob
can only remember one or neither of a person's parents). A person can
never be his/her own parent. Though Jim-Bob calls it his family tree,
it's more like just a collection of people he knows, some people might
not be related in any way to other people.
A good way to identify a redneck is by a strange family structure (for example, if their daughter is also their mother). If for any family member, one of their direct ancestors (parents, grandparents, etc.) is also one of their direct descendants (children, grandchildren, etc.), then that person is a redneck. If Jim-Bob is in any way related to a redneck, then he himself might be a redneck.
Now, Billy-Bob also isn't too bright, so he asks you to help him figure
it out. Given  
 cases of Jim-Bob's family tree,
determine whether or not he might be a redneck.
Input Specification
A single integer - .
For each case:
A single integer - .
The next  lines each contain information about a person - a string
, an integer 
, and then 
 names (the names of
person 
's parents, each of which will be one of the 
 people).
Output Specification
For each case, simply output Redneck or Not a redneck, depending
on whether or not Jim-Bob is related to any rednecks.
Sample Input
1
6
Jim-Bob 0
Mary-Ann 0
John 1 Matt
Bob-Jim 2 Jim-Bob Mary-Ann
Tina 1 John
Matt 1 Tina
Sample Output
Not a redneck
Explanation
John is a redneck since Matt is his father and also his grandson. This
also applies to Matt and Tina.
However, Jim-Bob is not related to any of them, and his own family is
quite normal (he and Mary-Ann have a son, Bob-Jim). Therefore, Jim-Bob
is definitely not a redneck.
Comments