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 と呼びます)。可能な種類は次の通りです。

  • 母が同じなら SIBLINGS を出力します。

  • BESSIE が ELSIE の直系子孫なら、ELSIE は母、祖母、曾祖母、高祖母などです。ELSIE is the (relation) of BESSIE を出力し、(relation) を適切な関係、例えば great-great-grand-mother にします。

  • ELSIE が 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.