2024春-A-4 Uniqueness of Topological Order
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
This is a problem given in the Graduate Entrance Exam in 2023: Given a directed graph G, you are supposed to tell if there exists a unique topological order of its vertices.
输入格式
Each input file contains one test case. For each case, the first line gives two positive integers (), the number of vertices in the graph, and (), the number of directed edges. Then lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 1 to . It is guaranteed that no duplicated edge is given.
输出格式
Output the vertices with the smallest in-degree in the first line, in ascending order. Then if there exists a unique topological order of all the vertices, first print in a line Yes
and then output the topological sequence in the next line. Or if the answer is no, just print in a line No
.
All the numbers in a line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.
样例
6 9
2 1
1 3
5 2
5 4
2 3
2 6
3 4
6 4
6 1
5
Yes
5 2 6 1 3 4
6 8
1 2
1 3
5 2
5 4
2 3
2 6
3 4
6 4
1 5
No
限制
对于所有的测试用例,限制为150 ms, 64 MB