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$ の直前か直後になります。

すべての制約を満たす順序を求めてください。必ず可能です。複数なら名前のアルファベット順で最初のもの:先頭に置ける牛で名前が最小の牛を選び、その先頭の合法順序の中で二番目の名前を最小にし、以降も同様です。

入力

1 行目は $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.