QOJ.ac

QOJ

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

#20943. صف الماشية

통계

يحلب Farmer John كل يوم أبقاره الثماني: Bessie, Buttercup, Belinda, Beatrice, Bella, Blue, Betsy, Sue.

الأبقار انتقائية وتطلب $N$ قيود ($1 \leq N \leq 7$) على الترتيب. كل قيد يقول «يجب حلب $X$ بجانب $Y$»، أي تكون $X$ قبل $Y$ مباشرة أو بعدها مباشرة.

ابحث عن ترتيب يحقق جميع القيود. مضمون وجوده. إن تعددت الحلول فأخرج الأول أبجديًا: أصغر اسم بين الأبقار الممكنة أولًا في ترتيب صالح، ثم أصغر اسم ثاني بين الترتيبات الصالحة بهذه الأولى، وهكذا.

الإدخال

السطر الأول يحتوي $N$. الأسطر $N$ التالية في كل منها الجملة X must be milked beside Y، حيث $X$ و$Y$ اسمان من الثمانية أعلاه.

الإخراج

أخرج ترتيبًا صالحًا في 8 أسطر، بقرة في كل سطر. إن تعددت فأخرج الأول أبجديًا.

أمثلة

الإدخال 1

3
Buttercup must be milked beside Bella
Blue must be milked beside Bella
Sue must be milked beside Beatrice

الإخراج 1

Beatrice
Sue
Belinda
Bessie
Betsy
Blue
Bella
Buttercup

نسبة المسألة: 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.