QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#21047. 가계도

통계

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.