QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 256 MB Points totaux : 100

#20943. 가축 줄 세우기

Statistiques

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.