QOJ.ac

QOJ

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

#20943. Kolejka bydła

통계

Farmer John codziennie doi osiem krów: Bessie, Buttercup, Belinda, Beatrice, Bella, Blue, Betsy, Sue.

Są wybredne i wymagają $N$ ograniczeń ($1 \leq N \leq 7$) kolejności. Każde mówi „$X$ musi być dojona obok $Y$”, czyli bezpośrednio przed lub po $Y$.

Znajdź kolejność spełniającą wszystkie ograniczenia. Zawsze istnieje. Jeśli jest kilka, wybierz pierwszą alfabetycznie: pierwsze imię najmniejsze wśród możliwych pierwszych krów poprawnych kolejek, następnie drugie najmniejsze wśród kolejek z tą pierwszą i tak dalej.

Wejście

Pierwszy wiersz zawiera $N$. Następne $N$ zawierają zdanie X must be milked beside Y, gdzie $X$, $Y$ są imionami z ośmiu powyżej.

Wyjście

Wypisz poprawną kolejność na 8 wierszach, po krowie na wiersz. Przy kilku wybierz pierwszą alfabetycznie.

Przykład

Wejście 1

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

Wyjście 1

Beatrice
Sue
Belinda
Bessie
Betsy
Blue
Bella
Buttercup

Autor zadania: 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.