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 is the (relation) of BESSIE עם הקשר המתאים, למשל 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 דודתה.

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.