|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||256 MB||0||0||0||0.000%|
Aunt Clara-May has been taking an interest in the genealogy of the family. She is able to construct a family tree but is getting confused with the relationships between different members of the family.
She wants to identify the following relationships: father, mother, uncle, aunt, son, daughter, nephew, niece, cousin, husband and wife. She also wants to be able to recognise whether the members in the family are related by blood or by marriage (i.e. in-laws), as well as different generations in the family such as grandparents, grandchildren, great grandparents, great grandchildren, great great grandparents, great great grandchildren etc. and different degrees of cousins including levels of removedness (e.g. second cousins-in-law twice removed).
Aunty C-M, as you call her, has some definitions of these relationships but needs your help to write a program to construct the family tree and name the relationships.
You have told Aunty C-M that you will help under the following conditions:
Further to those conditions, the following definitions apply:
motherare the parents of a child
sisterare male and female siblings with the same parents
daughterare the children of a parent
auntare the brother and sister of a child’s parent
nieceare the male and female children of a sibling
grandmotherare the male and female parents, respectively of a child’s parent
great grandmotherare the father and mother, respectively, of a child’s grandparent
great auntis a sibling to a child’s grandparent
cousins(not removed) are at the same level in the family tree
first cousin once removedis the child of one of the first cousins
first cousin twice removedis the grandchild of one of the first cousins
Figure 1 displays the family tree described in the Sample Input. Your program should be able to say that
Claire and Carol are 1st cousins,
Claire and Diva are 1st cousins 1-time removed, and
Claire and Chris are cousins-in-law. Your program should also be able to generate any other relationship combinations when queried.
Figure 1: Sample Input
The input contains a single test case.
The input consists of a list of relationships for construction of the family tree. The list of relationships will be followed by a list of queries for which you will name the relationship. Relationships will be provided to infer the gender of all family members.
All relationships will be in lower case and all names will be unique. At most one person in each marriage will have parents present in the input.
The first line of input contains a single integer r (1 ≤ r ≤ 200) being the number of relationships for building the family tree. r lines of relationship definitions follow. Each relationship consists of three alphabetic strings, name1, name2 and relation, each separated by a single space. relation will be one of
daughter. The relationship line can be read as:
name1 is the relation of name2
The relationships are followed by a line containing a single integer q (1 ≤ q ≤ 200) being the number of queries on the family tree. q query lines follow. Each query line consists of two strings, name1 and name2 separated by a single space. The names in the queries will be contained in the family tree.
For each relationship query, output the relationship between name1 and name2 on a single line.
In the following definitions mandatory items are delimited with
), optional items are delimited with
], options are separated by
|. Elements which may require repetition (1 to many) are followed by
wife, output a sentence of the following form:
name1 is the (husband|wife) of name2
sister, output a sentence of the following form:
name1 is the (brother|sister)[-in-law] of name2
3rdetc. followed by the word
cousins, then the suffix
-in-lawif and only if the relationship is by marriage and finally the number of times removed (
3-times removed, etc.).
name1 and name2 are (1st|2nd|3rd|...) cousins[-in-law][ (1-time|2-times|3-times|...) removed]
name1 is the [great ]*(aunt|uncle|nephew|niece)[-in-law] of name2
mother. Relationships which are two generations apart will require the use of the word
grandbefore the relationship. Relationships which are more than two generations apart will require the use of one or more instances of the word
greatbefore the word
name1 is the [[great ]*grand](son|daughter|father|mother)[-in-law] of name2
10 Alex Alice husband Ben Alex son Chase Ben son Diva Chase daughter Carol Ben daughter Belle Alex daughter Chris Chase wife Blake Belle husband Billie Ben wife Claire Belle daughter 10 Claire Carol Claire Diva Claire Chris Billie Belle Billie Chris Billie Chase Belle Carol Blake Carol Carol Belle Carol Blake
Claire and Carol are 1st cousins Claire and Diva are 1st cousins 1-time removed Claire and Chris are 1st cousins-in-law Billie is the sister-in-law of Belle Billie is the mother-in-law of Chris Billie is the mother of Chase Belle is the aunt of Carol Blake is the uncle-in-law of Carol Carol is the niece of Belle Carol is the niece-in-law of Blake