Remote Relatives X70643


Statement
 

pdf   zip

thehtml

In reference to a (possibly large) list of people, we receive from an adequate company information about pairs of names who are certainly remote relatives, on the basis of biological analyses. Of course, if a person is a certain relative of two others, these are in turn certain relatives among them. Which further links can we ascertain from the given pairs?

Input

Input has two parts. In the first part, a sequence of lines brings two names in each line, meaning that they are certain relatives. Names are strings having a single uppercase letter, namely, the capital initial. Then a line with the word "QUESTIONS" (and nothing else) comes, and then a sequence of questions which again consist of lines with two names on each. This second part might include names that did not appear in the first part.

Output

One line per question, repeating the two names in the question and followed by the words "Certain relatives" or "Uncertain", according to whether the data in the first part of the input implies that they are.

Observation

You must employ a disjoint-sets Union-Find data structure.

Public test cases
  • Input

    Finley Skyler
    Lennon Azariah
    Sidney Finley
    Denver Campbell
    Sidney Campbell
    Finley Denver
    Kylar Hollis
    Azariah Hollis
    Brighton Finley
    QUESTIONS
    Denver Sidney
    Lennon Azariah
    Hollis Sidney
    Lennon Kylar
    Jaidyn Brighton
    Skyler Campbell
    Denver Brighton

    Output

    Denver Sidney Certain relatives
    Lennon Azariah Certain relatives
    Hollis Sidney Uncertain
    Lennon Kylar Certain relatives
    Jaidyn Brighton Uncertain
    Skyler Campbell Certain relatives
    Denver Brighton Certain relatives
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python