#abc315e. E - Prerequisites
E - Prerequisites
Score : points
问题描述
我们有 本书,编号从 到 。
第 本书假设你已经阅读了 本书,其中第 本是书 :在阅读第 本书之前,你必须阅读所有这 本书。
在此条件下,你可以按照某种顺序阅读所有书籍。
你现在正尝试以最少的读书数量来读到书 。
请按阅读顺序输出除书 以外,你必须阅读的书的编号。在这种情况下,要读的书籍集合是唯一确定的。
如果存在多个满足条件的阅读顺序,你可以任选其中一个进行输出。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have books numbered to .
Book assumes that you have read books, the -th of which is book : you must read all these books before reading book .
Here, you can read all the books in some order.
You are trying to read the minimum number of books required to read book .
Print the numbers of the books you must read excluding book in the order they should be read. Under this condition, the set of books to read is uniquely determined.
If there are multiple reading orders that satisfy the condition, you may print any of them.
Constraints
- for .
- It is possible to read all the books.
Input
The input is given from Standard Input in the following format:
Output
Print the numbers of the books you must read to read book in the order they should be read, with spaces in between.
Sample Input 1
6
3 2 3 4
2 3 5
0
1 5
0
0
Sample Output 1
5 3 4 2
To read book , you must read books ; to read book , you must read books ; to read book , you must read book . To read books , you do not have to read any other books.
For example, if you read books in this order, you can read book . This is a correct answer, because you will never be able to read book with three or fewer books read. As another example, reading books in this order also allows you to read book with books read.
Sample Input 2
6
1 2
1 3
1 4
1 5
1 6
0
Sample Output 2
6 5 4 3 2
Sample Input 3
8
1 5
1 6
1 7
1 8
0
0
0
0
Sample Output 3
5
update @ 2024/3/10 09:00:59