QOJ.ac

QOJ

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

#21047. Cây gia đình

Statistics

Farmer John có nông trại gia đình truyền qua nhiều thế hệ, và gốc gia đình bò cũng truy được nhiều thế hệ ở đó. Xem hồ sơ cũ, ông muốn biết quan hệ trong đàn hiện tại. Hãy giúp!

Dữ liệu vào

Dòng đầu: $N$ ($1 \leq N \leq 100$) và tên hai cô bò. Mỗi tên là chuỗi tối đa $10$ chữ hoa ($A \ldots Z$). Ông hỏi quan hệ hai cô này.

$N$ dòng sau chứa tên $X$ và $Y$, cho biết $X$ là mẹ của $Y$.

Dữ liệu ra

In một dòng quan hệ hai cô ở dòng đầu (gọi BESSIE và ELSIE dưới đây cho đơn giản). Các loại có thể:

  • Cùng mẹ thì in SIBLINGS.

  • BESSIE có thể là hậu duệ trực tiếp của ELSIE, tức ELSIE là mẹ, bà, cụ, kỵ, v.v. In ELSIE is the (relation) of BESSIE, thay (relation) bằng quan hệ thích hợp như great-great-grand-mother.

  • Nếu ELSIE là con tổ tiên của BESSIE (không phải tổ tiên hay chị em của BESSIE), cô là dì của BESSIE. Con bà: ELSIE is the aunt of BESSIE; con cụ: ELSIE is the great-aunt of BESSIE; con kỵ: ELSIE is the great-great-aunt of BESSIE, v.v.

  • Quan hệ khác (chung tổ tiên) là chị em họ: in COUSINS.

  • Không chung tổ tiên, hoặc không cô nào là hậu duệ trực tiếp của cô kia, in NOT RELATED.

Sơ đồ minh họa các loại quan hệ duy nhất cần xét. “Cháu gái” (con gái của chị em) không cần: nếu BESSIE là cháu ELSIE, ELSIE là dì của BESSIE.

fig_familytree_bronze_open18.png

Ví dụ

Dữ liệu vào 1

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

Dữ liệu ra 1

BB is the great-aunt of AA

Tác giả bài toán: 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.