eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків

Papa

While cleaning your parents' attic, you discovered a box containing many documents describing the relationships among your ancestors. Given these documents, you are interested in answering a number of questions about the relationships implied by the document. Fortunately, all your ancestors have unique names so it is possible to make many inferences without any confusion. It is assumed that all relationships (implied or given) satisfy the following: \begin{itemize} \item A person can be either male, female, or have an unknown (undetermined by the data set) sex; \item a person can have at most one spouse (of the opposite sex), and \textbf{X} is \textbf{Y}'s wife if and only if \textbf{Y} is \textbf{X}'s husband; \item a person can have at most one mother and at most one father that can be inferred from the given data; \item if a person has a mother and father, then the mother and father are married; \item the children of a person's spouse are that person's children as well; \item the spouse of a son (or daughter) is not considered to be a daughter (or son). In other words, "sons" and "daughters" refer to biological sons and daughters. \end{itemize} The information provided will be consistent, and you may assume there are no hidden relationships that are not explicitly stated or implied by the above rules of consistency. \InputFile The first part of the input consists of a number of lines describing the known relationships. Each relationship is listed on one line in the form: \textbf{NAME is NAME's RELATIONSHIP.} where \textbf{NAME} is a lowercase alphabetic word (never 'is'), and \textbf{RELATIONSHIP} is one of \begin{itemize} \item wife \item husband \item daughter \item son \item mother \item father \end{itemize} This first part is terminated by a blank line. You may assume that there is at least one known relationship given, and there are at most \textbf{100} distinct names mentioned in the known relationships. This is followed by a list of questions (one per line) of the form: \textbf{is NAME NAME's RELATIONSHIP?} where \textbf{NAME} is as before, but \textbf{RELATIONSHIP} is one of \begin{itemize} \item wife \item husband \item daughter \item son \item mother \item father \item niece: \textbf{X} is a niece of \textbf{Y} if there are \textbf{W} and \textbf{Z} such that \textbf{X} is a daughter of \textbf{W}, and \textbf{W} and \textbf{Y} are distinct children of \textbf{Z}. \item nephew: \textbf{X} is a nephew of \textbf{Y} if there are \textbf{W} and \textbf{Z} such that \textbf{X} is a son of \textbf{W}, and \textbf{W} and \textbf{Y} are distinct children of \textbf{Z}. \item grandfather: \textbf{X} is a grandfather of \textbf{Y} if there is \textbf{Z} such that \textbf{X} is a father of \textbf{Z}, and \textbf{Z} is the father or mother of \textbf{Y}. \item grandmother: \textbf{X} is a grandmother of \textbf{Y} if there is \textbf{Z} such that \textbf{X} is a mother of \textbf{Z}, and \textbf{Z} is the father or mother of \textbf{Y}. \item grandson: \textbf{X} is a grandson of \textbf{Y} if there is \textbf{Z} such that \textbf{X} is a son of \textbf{Z}, and \textbf{Z} is a child of \textbf{Y}. \item granddaughter: \textbf{X} is a granddaughter of \textbf{Y} if there is \textbf{Z} such that \textbf{X} is a daughter of \textbf{Z}, and \textbf{Z} is a child of \textbf{Y}. \end{itemize} All names appearing in the questions will be mentioned in the list of known relationships. The list of questions is terminated by the end of file. \OutputFile For each question, print on a line yes or no if the answer of the question can be determined, or unknown if the answer may be yes or no because the sex of the relevant person(s) in the question cannot be determined from the known relationships.
Ліміт часу 3 секунди
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
john is mary's husband.
john is tom's father.
mary is jane's mother.
jane is anna's mother.

is mary john's wife?
is jane mary's daughter?
is tom mary's husband?
is anna jane's daughter?
Вихідні дані #1
yes
yes
no
unknown
Джерело Rocky Mountain Regional Contest 2009