QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21047. 家谱

Statistics

Farmer John 的家族农场已传承数代,牛群的家族根源也可追溯到同一农场的数代之前。他查阅旧记录,想知道当前牛群中奶牛之间的亲缘关系。请帮助他!

输入格式

第一行包含 $N$($1 \leq N \leq 100$),随后是两头奶牛的名字。名字是至多 $10$ 个大写字母($A \ldots Z$)组成的字符串。他想知道这一行两头奶牛的关系。

接下来 $N$ 行各包含两个名字 $X$ 和 $Y$,表示 $X$ 是 $Y$ 的母亲。

输出格式

输出一行,表示输入第一行两头奶牛的关系(为方便起见,以下示例称她们为 BESSIE 和 ELSIE)。可能的关系如下:

  • 若 BESSIE 和 ELSIE 母亲相同,输出 SIBLINGS。

  • BESSIE 可能是 ELSIE 的直系后代,即 ELSIE 是 BESSIE 的母亲、祖母、曾祖母、高祖母等。此时输出 ELSIE is the (relation) of BESSIE,其中 (relation) 是相应关系,如 great-great-grand-mother。

  • 若 ELSIE 是 BESSIE 某位祖先的孩子(且 ELSIE 本身并非 BESSIE 的祖先或姐妹),则 ELSIE 是 BESSIE 的姨母。若她是 BESSIE 祖母的孩子,输出 ELSIE is the aunt of BESSIE;若是曾祖母的孩子,输出 ELSIE is the great-aunt of BESSIE;若是高祖母的孩子,输出 ELSIE is the great-great-aunt of BESSIE,依此类推。

  • 若她们以其他方式有亲缘关系(即有共同祖先),则为表亲,直接输出 COUSINS。

  • 若她们没有共同祖先,或彼此都不是对方的直系后代,输出 NOT RELATED。

下图说明以上关系,这些是唯一需要考虑的类型。有些关系如“侄女”(姐妹的女儿)无需考虑,因为若 BESSIE 是 ELSIE 的侄女,则 ELSIE 是 BESSIE 的姨母。

fig_familytree_bronze_open18.png

样例

输入格式 1

7 AA BB
MOTHER AA
GGMOTHER BB
MOTHER SISTER
GMOTHER MOTHER
GMOTHER AUNT
AUNT COUSIN
GGMOTHER GMOTHER

输出格式 1

BB is the great-aunt of AA

题目作者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.