A Family Problem


Submit solution

Points: 2
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C++, Python3

This problem requires you to print the family tree in pre-order traversal.

Little Johnny Hottub wants to write a programme so that he can visualise his ancestries. He doesn't really care about siblings nor his ancestors' siblings, but he does want a good view of questions like who is his great-grandfather on his mother's side. Further more, he wants his classmate to be able to use this programme as well.

Input Specification

The first line will contain a single integer \(N\) (\(1 < N < 10000\)), indicating the number of test cases.

Each test case will start with an integer m, which is the total number of family members with detailed information. The integer is followed by the name of a root person: it can be either Johnny Hottub or one of his classmates' name.

The next m lines will begin each contain 3 names, the latter 2 being the mother and father of the first. The three names are separated by comma and a whitespace(", ")

Output Specification

Each test case should begin with the name of the root person in a single line. The entire family tree should be printed with 2 white spaces as indentation for each level, and the mother should always be printed before the father. Each line should contain one name only.

Test cases are separated by a single blank line.

Sample Input 1

3
1 Johnny Hottub
Johnny Hottub, Mama Hottub, Papa Hottub
3 Johnny Hottub
Mama Hottub, Susie Dent, Jimmy Carr
Johnny Hottub, Mama Hottub, Papa Hottub
Papa Hottub, Dame Hottub, Herr Hottub
7 Jolyne Kujo
Joseph Joestar, Elizabeth Joestar, George Joestar II
Sadao Kujo, Ernst Kujo, Victor Kujo
Jolyne Kujo, Mama Kujo, Jotaro Kujo
Jonathan Joestar, Mary Joestar, George Joestar
Jotaro Kujo, Holy Kujo, Sadao Kujo
Holy Kujo, Suzi Q Joestar, Joseph Joestar
George Joestar II, Erina Pendleton Joestar, Jonathan Joestar

Sample Output 1

Johnny Hottub
  Mama Hottub
  Papa Hottub

Johnny Hottub
  Mama Hottub
    Susie Dent
    Jimmy Carr
  Papa Hottub
    Dame Hottub
    Herr Hottub

Jolyne Kujo
  Mama Kujo
  Jotaro Kujo
    Holy Kujo
      Suzi Q Joestar
      Joseph Joestar
        Elizabeth Joestar
        George Joestar II
          Erina Pendleton Joestar
          Jonathan Joestar
            Mary Joestar
            George Joestar
    Sadao Kujo
      Ernst Kujo
      Victor Kujo

Comments

There are no comments at the moment.