Remote Relatives

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.

Problem information

Author: José Luis Balcázar

Generation: 2026-01-25T19:20:54.348Z

© Jutge.org, 2006–2026.
https://jutge.org
