You Might be a Redneck

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type

After 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 N (1 \le N \le 1\,000) people, including himself. Person i has a name n_i with no spaces in it. They also have p_i (0 \le p_i \le 2) 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 T (1 \le T \le 5) cases of Jim-Bob's family tree, determine whether or not he might be a redneck.

Input Specification

A single integer - T.
For each case:
A single integer - N.
The next N lines each contain information about a person - a string n_i, an integer p_i, and then p_i names (the names of person i's parents, each of which will be one of the N 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

There are no comments at the moment.