QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#20943. Xếp hàng gia súc

统计

Mỗi ngày Farmer John vắt sữa tám con bò: Bessie, Buttercup, Belinda, Beatrice, Bella, Blue, Betsy, Sue.

Chúng khá kén chọn và yêu cầu thứ tự đáp ứng $N$ ràng buộc ($1 \leq N \leq 7$). Mỗi ràng buộc là “$X$ phải vắt cạnh $Y$”, tức $X$ ngay trước hoặc ngay sau $Y$.

Tìm thứ tự đáp ứng tất cả ràng buộc. Luôn có. Nếu nhiều, chọn thứ tự đầu theo bảng chữ cái: tên đầu nhỏ nhất trong các con có thể đứng đầu một thứ tự hợp lệ, rồi tên thứ hai nhỏ nhất trong các thứ tự có cùng con đầu, cứ thế.

Dữ liệu vào

Dòng đầu chứa $N$. $N$ dòng tiếp chứa câu X must be milked beside Y, với $X$, $Y$ là tên trong tám con trên.

Dữ liệu ra

In thứ tự hợp lệ trên 8 dòng, mỗi dòng một con. Nếu nhiều, in thứ tự đầu theo bảng chữ cái.

Ví dụ

Dữ liệu vào 1

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

Dữ liệu ra 1

Beatrice
Sue
Belinda
Bessie
Betsy
Blue
Bella
Buttercup

Ghi công 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.